setup-java/__tests__/distributors/microsoft-installer.test.ts

89 lines
2.5 KiB
TypeScript
Raw Normal View History

2021-11-18 09:24:01 -08:00
import { MicrosoftDistributions } from '../../src/distributions/microsoft/installer';
describe('findPackageForDownload', () => {
let distribution: MicrosoftDistributions;
beforeEach(() => {
distribution = new MicrosoftDistributions({
version: '',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
});
});
it.each([
2021-11-18 14:53:03 -08:00
[
'17.x',
'17.0.1',
2021-11-19 10:50:41 -08:00
'https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
2021-11-18 14:53:03 -08:00
],
[
'16.0.x',
'16.0.2',
2021-11-19 10:50:41 -08:00
'https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
2021-11-18 14:53:03 -08:00
],
[
'11.0.13',
'11.0.13',
2021-11-19 10:50:41 -08:00
'https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
2021-11-18 14:53:03 -08:00
]
2021-11-18 09:24:01 -08:00
])('version is %s -> %s', async (input, expectedVersion, expectedUrl) => {
const result = await distribution['findPackageForDownload'](input);
expect(result.version).toBe(expectedVersion);
let os: string;
let archive: string;
2021-11-18 09:24:01 -08:00
switch (process.platform) {
2021-11-18 14:53:03 -08:00
case 'darwin':
os = 'macos';
2021-11-19 10:50:41 -08:00
archive = 'tar.gz';
2021-11-18 14:53:03 -08:00
break;
case 'win32':
os = 'windows';
2021-11-19 10:50:41 -08:00
archive = 'zip';
2021-11-18 14:53:03 -08:00
break;
default:
os = process.platform.toString();
2021-11-19 10:50:41 -08:00
archive = 'tar.gz';
2021-11-18 14:53:03 -08:00
break;
2021-11-18 09:24:01 -08:00
}
2021-11-19 10:50:41 -08:00
const url = expectedUrl.replace('{{OS_TYPE}}', os).replace('{{ARCHIVE_TYPE}}', archive);
expect(result.url).toBe(url);
2021-11-18 09:24:01 -08:00
});
it('should throw an error', async () => {
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow(
/Could not find satisfied version for SemVer */
2021-11-18 09:24:01 -08:00
);
});
});
describe('getPlatformOption', () => {
const distributions = new MicrosoftDistributions({
architecture: 'x64',
version: '11',
packageType: 'jdk',
checkLatest: false
});
it.each([
2021-11-19 10:50:41 -08:00
['linux', 'tar.gz', 'linux'],
['darwin', 'tar.gz', 'macos'],
['win32', 'zip', 'windows']
])('os version %s -> %s', (input, expectedArchive, expectedOs) => {
2021-11-18 09:24:01 -08:00
const actual = distributions['getPlatformOption'](input as NodeJS.Platform);
2021-11-19 10:50:41 -08:00
expect(actual.archive).toEqual(expectedArchive);
expect(actual.os).toEqual(expectedOs);
2021-11-18 09:24:01 -08:00
});
it.each(['aix', 'android', 'freebsd', 'openbsd', 'netbsd', 'solaris', 'cygwin'])(
'not support os version %s',
input => {
expect(() => distributions['getPlatformOption'](input as NodeJS.Platform)).toThrow(
/Platform '\w+' is not supported\. Supported platforms: .+/
);
}
);
});