1
0
Fork 0
mirror of https://github.com/actions/setup-java synced 2024-11-09 23:22:40 +00:00
setup-java/__tests__/distributors/zulu-installer.test.ts
Maxim Lobanov b53500dabc
Merge "v2-preview" branch into "main" (#150)
* actions/setup-java@v2 - Support different distributions (#132)

* Implement support for custom vendors in setup-java

* minor improvements

* minor refactoring

* Add unit tests and e2e tests

* Update documentation for setup-java@v2 release

* minor improvements

* regenerate dist

* fix comments

* resolve comments

* resolve comments

* fix tests

* Update README.md

Co-authored-by: George Adams <george.adams@microsoft.com>

* Apply suggestions from code review

Co-authored-by: Konrad Pabjan <konradpabjan@github.com>

* fix minor nitpicks

* handle 4th digit

* pull latest main

* Update README.md

* rename adoptium to adopt

* rename adoptium to adopt

* rename adoptium to adopt

* Update README.md

* make java-version and distribution required for action

* update readme

* fix tests

* fix e2e tests

Co-authored-by: George Adams <george.adams@microsoft.com>
Co-authored-by: Konrad Pabjan <konradpabjan@github.com>

* Add "overwrite-settings" input parameter (#136)

* add overwrite-settings parameter

* fix e2e tests

* print debug

* fix e2e tests

* add comment

* remove comment

* Add "Contents/Home" postfix on macOS if provider creates it (#139)

* Update e2e-versions.yml

* Update e2e-versions.yml

* implement fix

* Update e2e-versions.yml

* Update installer.ts

* fix filter logic

* Update e2e-versions.yml

* remove extra logic

* Update e2e-versions.yml

* Add check-latest flag (#141)

* add changes for check-latest

* run prerelease script

* resolving comments

* fixing tests

* fix spelling

* improve core.info messages

* run format

* run prerelease

* change version to fix test

* resolve comment for check-latest

* Update README.md

* added hosted tool cache section

* Apply suggestions from code review

Co-authored-by: Maxim Lobanov <v-malob@microsoft.com>
Co-authored-by: Konrad Pabjan <konradpabjan@github.com>

* Avoid "+" sign in Java path in v2-preview (#145)

* try to handle _ versions

* more logs

* more debug

* test 1

* more fixes

* fix typo

* Update e2e-versions.yml

* add unit-tests

* remove debug info from tests

* debug pre-cached versions

* change e2e tests to ubuntu-latest

* update npm licenses

Co-authored-by: George Adams <george.adams@microsoft.com>
Co-authored-by: Konrad Pabjan <konradpabjan@github.com>
Co-authored-by: Dmitry Shibanov <dmitry-shibanov@github.com>
2021-04-05 13:02:27 +03:00

165 lines
5.8 KiB
TypeScript

import { HttpClient } from '@actions/http-client';
import * as semver from 'semver';
import { ZuluDistribution } from '../../src/distributions/zulu/installer';
import { IZuluVersions } from '../../src/distributions/zulu/models';
import * as utils from '../../src/util';
const manifestData = require('../data/zulu-releases-default.json') as [];
describe('getAvailableVersions', () => {
let spyHttpClient: jest.SpyInstance;
let spyUtilGetDownloadArchiveExtension: jest.SpyInstance;
beforeEach(() => {
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
spyHttpClient.mockReturnValue({
statusCode: 200,
headers: {},
result: manifestData as IZuluVersions[]
});
spyUtilGetDownloadArchiveExtension = jest.spyOn(utils, 'getDownloadArchiveExtension');
spyUtilGetDownloadArchiveExtension.mockReturnValue('tar.gz');
});
afterEach(() => {
jest.resetAllMocks();
jest.clearAllMocks();
jest.restoreAllMocks();
});
it.each([
[
{ version: '11', architecture: 'x86', packageType: 'jdk', checkLatest: false },
'?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=x86&hw_bitness=32&release_status=ga'
],
[
{ version: '11-ea', architecture: 'x86', packageType: 'jdk', checkLatest: false },
'?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=x86&hw_bitness=32&release_status=ea'
],
[
{ version: '8', architecture: 'x64', packageType: 'jdk', checkLatest: false },
'?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=x86&hw_bitness=64&release_status=ga'
],
[
{ version: '8', architecture: 'x64', packageType: 'jre', checkLatest: false },
'?os=macos&ext=tar.gz&bundle_type=jre&javafx=false&arch=x86&hw_bitness=64&release_status=ga'
],
[
{ version: '8', architecture: 'x64', packageType: 'jdk+fx', checkLatest: false },
'?os=macos&ext=tar.gz&bundle_type=jdk&javafx=true&arch=x86&hw_bitness=64&release_status=ga&features=fx'
],
[
{ version: '8', architecture: 'x64', packageType: 'jre+fx', checkLatest: false },
'?os=macos&ext=tar.gz&bundle_type=jre&javafx=true&arch=x86&hw_bitness=64&release_status=ga&features=fx'
]
])('build correct url for %s -> %s', async (input, parsedUrl) => {
const distribution = new ZuluDistribution(input);
distribution['getPlatformOption'] = () => 'macos';
const buildUrl = `https://api.azul.com/zulu/download/community/v1.0/bundles/${parsedUrl}`;
await distribution['getAvailableVersions']();
expect(spyHttpClient.mock.calls).toHaveLength(1);
expect(spyHttpClient.mock.calls[0][0]).toBe(buildUrl);
});
it('load available versions', async () => {
const distribution = new ZuluDistribution({
version: '11',
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
});
const availableVersions = await distribution['getAvailableVersions']();
expect(availableVersions).toHaveLength(manifestData.length);
});
});
describe('getArchitectureOptions', () => {
it.each([
[{ architecture: 'x64' }, { arch: 'x86', hw_bitness: '64', abi: '' }],
[{ architecture: 'x86' }, { arch: 'x86', hw_bitness: '32', abi: '' }],
[{ architecture: 'x32' }, { arch: 'x32', hw_bitness: '', abi: '' }],
[{ architecture: 'arm' }, { arch: 'arm', hw_bitness: '', abi: '' }]
])('%s -> %s', (input, expected) => {
const distribution = new ZuluDistribution({
version: '11',
architecture: input.architecture,
packageType: 'jdk',
checkLatest: false
});
expect(distribution['getArchitectureOptions']()).toEqual(expected);
});
});
describe('findPackageForDownload', () => {
it.each([
['8', '8.0.282+8'],
['11.x', '11.0.10+9'],
['8.0', '8.0.282+8'],
['11.0.x', '11.0.10+9'],
['15', '15.0.2+7'],
['9.0.0', '9.0.0+0'],
['9.0', '9.0.1+0'],
['8.0.262', '8.0.262+19'], // validate correct choise between [8.0.262.17, 8.0.262.19, 8.0.262.18]
['8.0.262+17', '8.0.262+17'],
['15.0.1+8', '15.0.1+8'],
['15.0.1+9', '15.0.1+9']
])('version is %s -> %s', async (input, expected) => {
const distribution = new ZuluDistribution({
version: input,
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
});
distribution['getAvailableVersions'] = async () => manifestData;
const result = await distribution['findPackageForDownload'](distribution['version']);
expect(result.version).toBe(expected);
});
it('select correct bundle if there are multiple items with the same jdk version but different zulu versions', async () => {
const distribution = new ZuluDistribution({
version: '',
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
});
distribution['getAvailableVersions'] = async () => manifestData;
const result = await distribution['findPackageForDownload']('11.0.5');
expect(result.url).toBe(
'https://cdn.azul.com/zulu/bin/zulu11.35.15-ca-jdk11.0.5-macosx_x64.tar.gz'
);
});
it('should throw an error', async () => {
const distribution = new ZuluDistribution({
version: '18',
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
});
await expect(
distribution['findPackageForDownload'](distribution['version'])
).rejects.toThrowError(/Could not find satisfied version for semver */);
});
});
describe('convertVersionToSemver', () => {
it.each([
[[12], '12'],
[[12, 0], '12.0'],
[[12, 0, 2], '12.0.2'],
[[12, 0, 2, 1], '12.0.2+1'],
[[12, 0, 2, 1, 3], '12.0.2+1']
])('%s -> %s', (input: number[], expected: string) => {
const distribution = new ZuluDistribution({
version: '18',
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
});
const actual = distribution['convertVersionToSemver'](input);
expect(actual).toBe(expected);
});
});