2023-03-09 20:49:35 +08:00
|
|
|
import {OracleDistribution} from '../../src/distributions/oracle/installer';
|
2023-02-07 23:29:21 +08:00
|
|
|
import os from 'os';
|
|
|
|
import * as core from '@actions/core';
|
2023-03-09 20:49:35 +08:00
|
|
|
import {getDownloadArchiveExtension} from '../../src/util';
|
2023-06-07 22:18:29 +08:00
|
|
|
import {HttpClient} from '@actions/http-client';
|
2023-02-07 23:29:21 +08:00
|
|
|
|
|
|
|
describe('findPackageForDownload', () => {
|
|
|
|
let distribution: OracleDistribution;
|
|
|
|
let spyDebug: jest.SpyInstance;
|
2023-06-07 22:18:29 +08:00
|
|
|
let spyHttpClient: jest.SpyInstance;
|
2023-02-07 23:29:21 +08:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
distribution = new OracleDistribution({
|
|
|
|
version: '',
|
|
|
|
architecture: 'x64',
|
|
|
|
packageType: 'jdk',
|
|
|
|
checkLatest: false
|
|
|
|
});
|
|
|
|
|
|
|
|
spyDebug = jest.spyOn(core, 'debug');
|
|
|
|
spyDebug.mockImplementation(() => {});
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
2023-12-14 21:46:05 +08:00
|
|
|
[
|
|
|
|
'21',
|
|
|
|
'21',
|
|
|
|
'https://download.oracle.com/java/21/latest/jdk-21_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
|
|
|
|
],
|
2023-02-07 23:29:21 +08:00
|
|
|
[
|
2023-05-06 17:54:05 +08:00
|
|
|
'20',
|
|
|
|
'20',
|
2023-07-18 15:28:12 +08:00
|
|
|
'https://download.oracle.com/java/20/latest/jdk-20_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'18',
|
|
|
|
'18',
|
|
|
|
'https://download.oracle.com/java/18/archive/jdk-18_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
|
2023-02-07 23:29:21 +08:00
|
|
|
],
|
|
|
|
[
|
2023-05-06 17:54:05 +08:00
|
|
|
'20.0.1',
|
|
|
|
'20.0.1',
|
|
|
|
'https://download.oracle.com/java/20/archive/jdk-20.0.1_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
|
2023-02-07 23:29:21 +08:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'17',
|
|
|
|
'17',
|
2023-07-18 15:28:12 +08:00
|
|
|
'https://download.oracle.com/java/17/latest/jdk-17_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
|
2023-02-07 23:29:21 +08:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'17.0.1',
|
|
|
|
'17.0.1',
|
|
|
|
'https://download.oracle.com/java/17/archive/jdk-17.0.1_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
|
|
|
|
]
|
|
|
|
])('version is %s -> %s', async (input, expectedVersion, expectedUrl) => {
|
2023-06-08 18:15:00 +08:00
|
|
|
/* Needed only for this particular test because some urls might change */
|
2023-06-07 22:18:29 +08:00
|
|
|
spyHttpClient = jest.spyOn(HttpClient.prototype, 'head');
|
|
|
|
spyHttpClient.mockReturnValue(
|
|
|
|
Promise.resolve({
|
|
|
|
message: {
|
|
|
|
statusCode: 200
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2023-07-18 15:28:12 +08:00
|
|
|
/**
|
|
|
|
* NOTE - Should fail to retrieve 18 from latest and check archive instead
|
|
|
|
*/
|
|
|
|
if (input === '18') {
|
|
|
|
spyHttpClient.mockReturnValueOnce(
|
|
|
|
Promise.resolve({
|
|
|
|
message: {
|
|
|
|
statusCode: 404
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-07 23:29:21 +08:00
|
|
|
const result = await distribution['findPackageForDownload'](input);
|
2023-06-07 22:18:29 +08:00
|
|
|
|
|
|
|
jest.restoreAllMocks();
|
|
|
|
|
2023-02-07 23:29:21 +08:00
|
|
|
expect(result.version).toBe(expectedVersion);
|
|
|
|
const osType = distribution.getPlatform();
|
|
|
|
const archiveType = getDownloadArchiveExtension();
|
2023-03-09 20:49:35 +08:00
|
|
|
const url = expectedUrl
|
|
|
|
.replace('{{OS_TYPE}}', osType)
|
|
|
|
.replace('{{ARCHIVE_TYPE}}', archiveType);
|
2023-02-07 23:29:21 +08:00
|
|
|
expect(result.url).toBe(url);
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
|
|
|
['amd64', 'x64'],
|
|
|
|
['arm64', 'aarch64']
|
|
|
|
])(
|
|
|
|
'defaults to os.arch(): %s mapped to distro arch: %s',
|
|
|
|
async (osArch: string, distroArch: string) => {
|
|
|
|
jest.spyOn(os, 'arch').mockReturnValue(osArch);
|
|
|
|
jest.spyOn(os, 'platform').mockReturnValue('linux');
|
|
|
|
|
2023-07-18 15:28:12 +08:00
|
|
|
const version = '18';
|
2023-02-07 23:29:21 +08:00
|
|
|
const distro = new OracleDistribution({
|
|
|
|
version,
|
|
|
|
architecture: '', // to get default value
|
|
|
|
packageType: 'jdk',
|
|
|
|
checkLatest: false
|
|
|
|
});
|
|
|
|
|
|
|
|
const osType = distribution.getPlatform();
|
|
|
|
if (osType === 'windows' && distroArch == 'aarch64') {
|
|
|
|
return; // skip, aarch64 is not available for Windows
|
|
|
|
}
|
|
|
|
const archiveType = getDownloadArchiveExtension();
|
|
|
|
const result = await distro['findPackageForDownload'](version);
|
2023-07-18 15:28:12 +08:00
|
|
|
const expectedUrl = `https://download.oracle.com/java/18/archive/jdk-18_${osType}-${distroArch}_bin.${archiveType}`;
|
2023-02-07 23:29:21 +08:00
|
|
|
|
|
|
|
expect(result.url).toBe(expectedUrl);
|
2024-06-28 07:34:36 +08:00
|
|
|
},
|
|
|
|
10000
|
2023-02-07 23:29:21 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
it('should throw an error', async () => {
|
|
|
|
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow(
|
|
|
|
/Oracle JDK is only supported for JDK 17 and later/
|
|
|
|
);
|
|
|
|
await expect(distribution['findPackageForDownload']('11')).rejects.toThrow(
|
|
|
|
/Oracle JDK is only supported for JDK 17 and later/
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|