Skip to content

Commit 07b6c30

Browse files
Add mocks for oracle installer
1 parent c19d52b commit 07b6c30

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

__tests__/distributors/oracle-installer.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import {OracleDistribution} from '../../src/distributions/oracle/installer';
22
import os from 'os';
33
import * as core from '@actions/core';
44
import {getDownloadArchiveExtension} from '../../src/util';
5+
import {HttpClient} from '@actions/http-client';
56

67
describe('findPackageForDownload', () => {
78
let distribution: OracleDistribution;
89
let spyDebug: jest.SpyInstance;
10+
let spyHttpClient: jest.SpyInstance;
911

1012
beforeEach(() => {
1113
distribution = new OracleDistribution({
@@ -41,7 +43,20 @@ describe('findPackageForDownload', () => {
4143
'https://download.oracle.com/java/17/archive/jdk-17.0.1_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
4244
]
4345
])('version is %s -> %s', async (input, expectedVersion, expectedUrl) => {
46+
/* Needed only for this particular test because /latest/ urls tend to change */
47+
spyHttpClient = jest.spyOn(HttpClient.prototype, 'head');
48+
spyHttpClient.mockReturnValue(
49+
Promise.resolve({
50+
message: {
51+
statusCode: 200
52+
}
53+
})
54+
);
55+
4456
const result = await distribution['findPackageForDownload'](input);
57+
58+
jest.restoreAllMocks();
59+
4560
expect(result.version).toBe(expectedVersion);
4661
const osType = distribution.getPlatform();
4762
const archiveType = getDownloadArchiveExtension();

0 commit comments

Comments
 (0)