Use archive as fallback only when dealing with major version

This commit is contained in:
Nikolai Laevskii
2023-07-18 09:28:12 +02:00
parent ebe05e0f88
commit 33b10b64eb
3 changed files with 79 additions and 25 deletions

View File

@ -25,7 +25,12 @@ describe('findPackageForDownload', () => {
[
'20',
'20',
'https://download.oracle.com/java/20/archive/jdk-20_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
'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}}'
],
[
'20.0.1',
@ -35,7 +40,7 @@ describe('findPackageForDownload', () => {
[
'17',
'17',
'https://download.oracle.com/java/17/archive/jdk-17_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
'https://download.oracle.com/java/17/latest/jdk-17_{{OS_TYPE}}-x64_bin.{{ARCHIVE_TYPE}}'
],
[
'17.0.1',
@ -53,6 +58,19 @@ describe('findPackageForDownload', () => {
})
);
/**
* NOTE - Should fail to retrieve 18 from latest and check archive instead
*/
if (input === '18') {
spyHttpClient.mockReturnValueOnce(
Promise.resolve({
message: {
statusCode: 404
}
})
);
}
const result = await distribution['findPackageForDownload'](input);
jest.restoreAllMocks();
@ -75,7 +93,7 @@ describe('findPackageForDownload', () => {
jest.spyOn(os, 'arch').mockReturnValue(osArch);
jest.spyOn(os, 'platform').mockReturnValue('linux');
const version = '17';
const version = '18';
const distro = new OracleDistribution({
version,
architecture: '', // to get default value
@ -89,7 +107,7 @@ describe('findPackageForDownload', () => {
}
const archiveType = getDownloadArchiveExtension();
const result = await distro['findPackageForDownload'](version);
const expectedUrl = `https://download.oracle.com/java/17/archive/jdk-17_${osType}-${distroArch}_bin.${archiveType}`;
const expectedUrl = `https://download.oracle.com/java/18/archive/jdk-18_${osType}-${distroArch}_bin.${archiveType}`;
expect(result.url).toBe(expectedUrl);
}