1
0
Fork 0
mirror of https://github.com/actions/setup-java synced 2024-12-22 21:22:41 +00:00

Fix adopt tests

This commit is contained in:
John Oliver 2023-10-17 15:19:09 +01:00
parent 23f68c75ed
commit f9217513b1

View file

@ -7,6 +7,7 @@ import {JavaInstallerOptions} from '../../src/distributions/base-models';
import os from 'os';
import temurinManifestData from '../data/temurin.json';
import manifestData from '../data/adopt.json';
import {
TemurinDistribution,
@ -18,11 +19,21 @@ describe('getAvailableVersions', () => {
beforeEach(() => {
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
spyHttpClient.mockReturnValue({
statusCode: 200,
headers: {},
result: []
});
spyHttpClient
.mockImplementation((requestUrl, additionalHeaders) => {
if (requestUrl.startsWith('https://api.adoptium.net/')) {
return {
statusCode: 200,
headers: {},
result: []
} as any;
}
})
.mockReturnValue({
statusCode: 200,
headers: {},
result: []
});
});
afterEach(() => {
@ -135,6 +146,15 @@ describe('getAvailableVersions', () => {
it('load available versions', async () => {
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
spyHttpClient
.mockImplementation((requestUrl, additionalHeaders) => {
if (requestUrl.startsWith('https://api.adoptium.net/')) {
return {
statusCode: 200,
headers: {},
result: []
} as any;
}
})
.mockReturnValueOnce({
statusCode: 200,
headers: {},
@ -236,6 +256,17 @@ describe('findPackageForDownload', () => {
['15.0.1+9', '15.0.1+9'],
['15.0.1+9.1', '15.0.1+9.1']
])('version is resolved correctly %s -> %s', async (input, expected) => {
const temurinDistribution = new TemurinDistribution(
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
TemurinImplementation.Hotspot
);
temurinDistribution['getAvailableVersions'] = async () => [] as any;
const distribution = new AdoptDistribution(
{
version: '11',
@ -243,26 +274,23 @@ describe('findPackageForDownload', () => {
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.Hotspot
AdoptImplementation.Hotspot,
temurinDistribution
);
distribution['getAvailableVersions'] = async () => manifestData as any;
const resolvedVersion = await distribution['findPackageForDownload'](input);
expect(resolvedVersion.version).toBe(expected);
});
describe('delegates to Temurin', () => {
it.each([
['9', '9.0.7+10'],
['15', '15.0.2+7'],
['15.0', '15.0.2+7'],
['15.0.2', '15.0.2+7'],
['15.0.1', '15.0.1+9.1'],
['11.x', '11.0.10+9'],
['x', '15.0.2+7'],
['12', '12.0.2+10.3'], // make sure that '12.0.2+10.1', '12.0.2+10.3', '12.0.2+10.2' are sorted correctly
['12.0.2+10.1', '12.0.2+10.1'],
['15.0.1+9', '15.0.1+9'],
['15.0.1+9.1', '15.0.1+9.1']
['8', '8.0.302+8'],
['16', '16.0.2+7'],
['16.0', '16.0.2+7'],
['16.0.2', '16.0.2+7'],
['8.x', '8.0.302+8'],
['x', '16.0.2+7']
])('version is resolved correctly %s -> %s', async (input, expected) => {
const temurinDistribution = new TemurinDistribution(
{
@ -273,6 +301,8 @@ describe('findPackageForDownload', () => {
},
TemurinImplementation.Hotspot
);
temurinDistribution['getAvailableVersions'] = async () =>
temurinManifestData as any;
const distribution = new AdoptDistribution(
{
@ -285,11 +315,13 @@ describe('findPackageForDownload', () => {
temurinDistribution
);
temurinDistribution['getAvailableVersions'] = async () =>
manifestData as any;
const resolvedVersion = await distribution['findPackageForDownload'](
input
);
distribution['findPackageForDownload'] = async () => {
throw new Error(`Could not find satisfied version`);
};
const resolvedVersion = await temurinDistribution[
'findPackageForDownload'
](input);
expect(resolvedVersion.version).toBe(expected);
});
});
@ -334,6 +366,16 @@ describe('findPackageForDownload', () => {
});
it('version is found but binaries list is empty', async () => {
const temurinDistribution = new TemurinDistribution(
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
TemurinImplementation.Hotspot
);
temurinDistribution['getAvailableVersions'] = async () => [] as any;
const distribution = new AdoptDistribution(
{
version: '11',
@ -341,13 +383,24 @@ describe('findPackageForDownload', () => {
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.Hotspot
AdoptImplementation.Hotspot,
temurinDistribution
);
distribution['getAvailableVersions'] = async () => manifestData as any;
await expect(
distribution['findPackageForDownload']('9.0.8')
).rejects.toThrow(/Could not find satisfied version for SemVer */);
});
const temurinDistribution = new TemurinDistribution(
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
TemurinImplementation.Hotspot
);
temurinDistribution['getAvailableVersions'] = async () => [] as any;
it('version is not found', async () => {
const distribution = new AdoptDistribution(
@ -357,7 +410,8 @@ describe('findPackageForDownload', () => {
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.Hotspot
AdoptImplementation.Hotspot,
temurinDistribution
);
distribution['getAvailableVersions'] = async () => manifestData as any;
await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrow(
@ -366,6 +420,23 @@ describe('findPackageForDownload', () => {
});
it('version list is empty', async () => {
let spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
spyHttpClient.mockImplementation((requestUrl, additionalHeaders) => {
if (requestUrl.startsWith('https://api.adoptium.net/')) {
return {
statusCode: 200,
headers: {},
result: []
} as any;
}
return {
statusCode: 200,
headers: {},
result: manifestData as any
} as any;
});
const distribution = new AdoptDistribution(
{
version: '11',