Add and configure ESLint and update configuration for Prettier (#458)

* Add ESLint config and update Prettier

* Update test files

* Rebuild action

* Update docs

* Update licenses

* Update tsconfig

* Rebuild action

* Update tsconfig.json

* Fix console.time calls

* Rebuild action

* Rebuild action on Linux
This commit is contained in:
Ivan
2023-03-09 14:49:35 +02:00
committed by GitHub
parent ea15b3b99c
commit 0de5c66fc0
55 changed files with 4402 additions and 1317 deletions

View File

@ -1,11 +1,14 @@
import { HttpClient } from '@actions/http-client';
import { AdoptDistribution, AdoptImplementation } from '../../src/distributions/adopt/installer';
import { JavaInstallerOptions } from '../../src/distributions/base-models';
import {HttpClient} from '@actions/http-client';
import {IAdoptAvailableVersions} from '../../src/distributions/adopt/models';
import {
AdoptDistribution,
AdoptImplementation
} from '../../src/distributions/adopt/installer';
import {JavaInstallerOptions} from '../../src/distributions/base-models';
import os from 'os';
let manifestData = require('../data/adopt.json') as [];
import manifestData from '../data/adopt.json';
describe('getAvailableVersions', () => {
let spyHttpClient: jest.SpyInstance;
@ -27,42 +30,82 @@ describe('getAvailableVersions', () => {
it.each([
[
{ version: '11', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.Hotspot,
'os=mac&architecture=x64&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=0'
],
[
{ version: '11', architecture: 'x86', packageType: 'jdk', checkLatest: false },
{
version: '11',
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.Hotspot,
'os=mac&architecture=x86&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=0'
],
[
{ version: '11', architecture: 'x64', packageType: 'jre', checkLatest: false },
{
version: '11',
architecture: 'x64',
packageType: 'jre',
checkLatest: false
},
AdoptImplementation.Hotspot,
'os=mac&architecture=x64&image_type=jre&release_type=ga&jvm_impl=hotspot&page_size=20&page=0'
],
[
{ version: '11-ea', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '11-ea',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.Hotspot,
'os=mac&architecture=x64&image_type=jdk&release_type=ea&jvm_impl=hotspot&page_size=20&page=0'
],
[
{ version: '11', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.OpenJ9,
'os=mac&architecture=x64&image_type=jdk&release_type=ga&jvm_impl=openj9&page_size=20&page=0'
],
[
{ version: '11', architecture: 'x86', packageType: 'jdk', checkLatest: false },
{
version: '11',
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.OpenJ9,
'os=mac&architecture=x86&image_type=jdk&release_type=ga&jvm_impl=openj9&page_size=20&page=0'
],
[
{ version: '11', architecture: 'x64', packageType: 'jre', checkLatest: false },
{
version: '11',
architecture: 'x64',
packageType: 'jre',
checkLatest: false
},
AdoptImplementation.OpenJ9,
'os=mac&architecture=x64&image_type=jre&release_type=ga&jvm_impl=openj9&page_size=20&page=0'
],
[
{ version: '11-ea', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '11-ea',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.OpenJ9,
'os=mac&architecture=x64&image_type=jdk&release_type=ea&jvm_impl=openj9&page_size=20&page=0'
]
@ -74,7 +117,8 @@ describe('getAvailableVersions', () => {
expectedParameters
) => {
const distribution = new AdoptDistribution(installerOptions, impl);
const baseUrl = 'https://api.adoptopenjdk.net/v3/assets/version/%5B1.0,100.0%5D';
const baseUrl =
'https://api.adoptopenjdk.net/v3/assets/version/%5B1.0,100.0%5D';
const expectedUrl = `${baseUrl}?project=jdk&vendor=adoptopenjdk&heap_size=normal&sort_method=DEFAULT&sort_order=DESC&${expectedParameters}`;
distribution['getPlatformOption'] = () => 'mac';
@ -91,12 +135,12 @@ describe('getAvailableVersions', () => {
.mockReturnValueOnce({
statusCode: 200,
headers: {},
result: manifestData
result: manifestData as any
})
.mockReturnValueOnce({
statusCode: 200,
headers: {},
result: manifestData
result: manifestData as any
})
.mockReturnValueOnce({
statusCode: 200,
@ -105,7 +149,12 @@ describe('getAvailableVersions', () => {
});
const distribution = new AdoptDistribution(
{ version: '11', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.Hotspot
);
const availableVersions = await distribution['getAvailableVersions']();
@ -122,7 +171,12 @@ describe('getAvailableVersions', () => {
'find right toolchain folder',
(impl: AdoptImplementation, packageType: string, expected: string) => {
const distribution = new AdoptDistribution(
{ version: '11', architecture: 'x64', packageType: packageType, checkLatest: false },
{
version: '11',
architecture: 'x64',
packageType: packageType,
checkLatest: false
},
impl
);
@ -148,8 +202,12 @@ describe('getAvailableVersions', () => {
const expectedParameters = `os=mac&architecture=${distroArch}&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=0`;
const distribution = new AdoptDistribution(installerOptions, AdoptImplementation.Hotspot);
const baseUrl = 'https://api.adoptopenjdk.net/v3/assets/version/%5B1.0,100.0%5D';
const distribution = new AdoptDistribution(
installerOptions,
AdoptImplementation.Hotspot
);
const baseUrl =
'https://api.adoptopenjdk.net/v3/assets/version/%5B1.0,100.0%5D';
const expectedUrl = `${baseUrl}?project=jdk&vendor=adoptopenjdk&heap_size=normal&sort_method=DEFAULT&sort_order=DESC&${expectedParameters}`;
distribution['getPlatformOption'] = () => 'mac';
@ -176,43 +234,63 @@ describe('findPackageForDownload', () => {
['15.0.1+9.1', '15.0.1+9.1']
])('version is resolved correctly %s -> %s', async (input, expected) => {
const distribution = new AdoptDistribution(
{ version: '11', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.Hotspot
);
distribution['getAvailableVersions'] = async () => manifestData;
distribution['getAvailableVersions'] = async () => manifestData as any;
const resolvedVersion = await distribution['findPackageForDownload'](input);
expect(resolvedVersion.version).toBe(expected);
});
it('version is found but binaries list is empty', async () => {
const distribution = new AdoptDistribution(
{ version: '11', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.Hotspot
);
distribution['getAvailableVersions'] = async () => manifestData;
await expect(distribution['findPackageForDownload']('9.0.8')).rejects.toThrowError(
/Could not find satisfied version for SemVer */
);
distribution['getAvailableVersions'] = async () => manifestData as any;
await expect(
distribution['findPackageForDownload']('9.0.8')
).rejects.toThrow(/Could not find satisfied version for SemVer */);
});
it('version is not found', async () => {
const distribution = new AdoptDistribution(
{ version: '11', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.Hotspot
);
distribution['getAvailableVersions'] = async () => manifestData;
await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrowError(
distribution['getAvailableVersions'] = async () => manifestData as any;
await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrow(
/Could not find satisfied version for SemVer */
);
});
it('version list is empty', async () => {
const distribution = new AdoptDistribution(
{ version: '11', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.Hotspot
);
distribution['getAvailableVersions'] = async () => [];
await expect(distribution['findPackageForDownload']('11')).rejects.toThrowError(
await expect(distribution['findPackageForDownload']('11')).rejects.toThrow(
/Could not find satisfied version for SemVer */
);
});

View File

@ -5,7 +5,7 @@ import * as util from '../../src/util';
import path from 'path';
import * as semver from 'semver';
import { JavaBase } from '../../src/distributions/base-installer';
import {JavaBase} from '../../src/distributions/base-installer';
import {
JavaDownloadRelease,
JavaInstallerOptions,
@ -19,14 +19,23 @@ class EmptyJavaBase extends JavaBase {
super('Empty', installerOptions);
}
protected async downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults> {
protected async downloadTool(
javaRelease: JavaDownloadRelease
): Promise<JavaInstallerResults> {
return {
version: '11.0.9',
path: path.join('toolcache', this.toolcacheFolderName, '11.0.9', this.architecture)
path: path.join(
'toolcache',
this.toolcacheFolderName,
'11.0.9',
this.architecture
)
};
}
protected async findPackageForDownload(range: string): Promise<JavaDownloadRelease> {
protected async findPackageForDownload(
range: string
): Promise<JavaDownloadRelease> {
const availableVersion = '11.0.9';
if (!semver.satisfies(availableVersion, range)) {
throw new Error('Available version not found');
@ -60,44 +69,111 @@ describe('findInToolcache', () => {
it.each([
[
{ version: '11', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{ version: actualJavaVersion, path: javaPath }
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
{version: actualJavaVersion, path: javaPath}
],
[
{ version: '11.0', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{ version: actualJavaVersion, path: javaPath }
{
version: '11.0',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
{version: actualJavaVersion, path: javaPath}
],
[
{ version: '11.0.8', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{ version: actualJavaVersion, path: javaPath }
{
version: '11.0.8',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
{version: actualJavaVersion, path: javaPath}
],
[
{ version: '11', architecture: 'x64', packageType: 'jdk', checkLatest: true },
{ version: actualJavaVersion, path: javaPath }
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: true
},
{version: actualJavaVersion, path: javaPath}
],
[
{ version: '11.0', architecture: 'x64', packageType: 'jdk', checkLatest: true },
{ version: actualJavaVersion, path: javaPath }
{
version: '11.0',
architecture: 'x64',
packageType: 'jdk',
checkLatest: true
},
{version: actualJavaVersion, path: javaPath}
],
[
{ version: '11.0.8', architecture: 'x64', packageType: 'jdk', checkLatest: true },
{ version: actualJavaVersion, path: javaPath }
{
version: '11.0.8',
architecture: 'x64',
packageType: 'jdk',
checkLatest: true
},
{version: actualJavaVersion, path: javaPath}
],
[{ version: '11', architecture: 'x64', packageType: 'jre', checkLatest: false }, null],
[{ version: '8', architecture: 'x64', packageType: 'jdk', checkLatest: false }, null],
[{ version: '11', architecture: 'x86', packageType: 'jdk', checkLatest: false }, null],
[{ version: '11', architecture: 'x86', packageType: 'jre', checkLatest: false }, null]
[
{
version: '11',
architecture: 'x64',
packageType: 'jre',
checkLatest: false
},
null
],
[
{
version: '8',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
null
],
[
{
version: '11',
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
},
null
],
[
{
version: '11',
architecture: 'x86',
packageType: 'jre',
checkLatest: false
},
null
]
])(`should find java for path %s -> %s`, (input, expected) => {
spyTcFindAllVersions.mockReturnValue([actualJavaVersion]);
spyGetToolcachePath.mockImplementation(
(toolname: string, javaVersion: string, architecture: string) => {
const semverVersion = new semver.Range(javaVersion);
if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) {
if (
path.basename(javaPath) !== architecture ||
!javaPath.includes(toolname)
) {
return '';
}
return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : '';
return semver.satisfies(actualJavaVersion, semverVersion)
? javaPath
: '';
}
);
mockJavaBase = new EmptyJavaBase(input);
@ -105,52 +181,63 @@ describe('findInToolcache', () => {
});
it.each([
['11', { version: '11.0.3+2', versionInPath: '11.0.3-2' }],
['11.0', { version: '11.0.3+2', versionInPath: '11.0.3-2' }],
['11.0.1', { version: '11.0.1', versionInPath: '11.0.1' }],
['11.0.3', { version: '11.0.3+2', versionInPath: '11.0.3-2' }],
['15', { version: '15.0.2+4', versionInPath: '15.0.2-4' }],
['x', { version: '15.0.2+4', versionInPath: '15.0.2-4' }],
['x-ea', { version: '17.4.4', versionInPath: '17.4.4-ea' }],
['11-ea', { version: '11.3.3+5.2.1231421', versionInPath: '11.3.3-ea.5.2.1231421' }],
['11.2-ea', { version: '11.2.1', versionInPath: '11.2.1-ea' }],
['11.2.1-ea', { version: '11.2.1', versionInPath: '11.2.1-ea' }]
])('should choose correct java from tool-cache for input %s', (input, expected) => {
spyTcFindAllVersions.mockReturnValue([
'17.4.4-ea',
'11.0.2',
'15.0.2-4',
'11.0.3-2',
'11.2.1-ea',
'11.3.2-ea',
'11.3.2-ea.5',
'11.3.3-ea.5.2.1231421',
'12.3.2-0',
'11.0.1'
]);
spyGetToolcachePath.mockImplementation(
(toolname: string, javaVersion: string, architecture: string) =>
`/hostedtoolcache/${toolname}/${javaVersion}/${architecture}`
);
mockJavaBase = new EmptyJavaBase({
version: input,
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
});
const foundVersion = mockJavaBase['findInToolcache']();
expect(foundVersion).toEqual({
version: expected.version,
path: `/hostedtoolcache/Java_Empty_jdk/${expected.versionInPath}/x64`
});
});
['11', {version: '11.0.3+2', versionInPath: '11.0.3-2'}],
['11.0', {version: '11.0.3+2', versionInPath: '11.0.3-2'}],
['11.0.1', {version: '11.0.1', versionInPath: '11.0.1'}],
['11.0.3', {version: '11.0.3+2', versionInPath: '11.0.3-2'}],
['15', {version: '15.0.2+4', versionInPath: '15.0.2-4'}],
['x', {version: '15.0.2+4', versionInPath: '15.0.2-4'}],
['x-ea', {version: '17.4.4', versionInPath: '17.4.4-ea'}],
[
'11-ea',
{version: '11.3.3+5.2.1231421', versionInPath: '11.3.3-ea.5.2.1231421'}
],
['11.2-ea', {version: '11.2.1', versionInPath: '11.2.1-ea'}],
['11.2.1-ea', {version: '11.2.1', versionInPath: '11.2.1-ea'}]
])(
'should choose correct java from tool-cache for input %s',
(input, expected) => {
spyTcFindAllVersions.mockReturnValue([
'17.4.4-ea',
'11.0.2',
'15.0.2-4',
'11.0.3-2',
'11.2.1-ea',
'11.3.2-ea',
'11.3.2-ea.5',
'11.3.3-ea.5.2.1231421',
'12.3.2-0',
'11.0.1'
]);
spyGetToolcachePath.mockImplementation(
(toolname: string, javaVersion: string, architecture: string) =>
`/hostedtoolcache/${toolname}/${javaVersion}/${architecture}`
);
mockJavaBase = new EmptyJavaBase({
version: input,
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
});
const foundVersion = mockJavaBase['findInToolcache']();
expect(foundVersion).toEqual({
version: expected.version,
path: `/hostedtoolcache/Java_Empty_jdk/${expected.versionInPath}/x64`
});
}
);
});
describe('setupJava', () => {
const actualJavaVersion = '11.0.9';
const installedJavaVersion = '11.0.8';
const javaPath = path.join('Java_Empty_jdk', installedJavaVersion, 'x86');
const javaPathInstalled = path.join('toolcache', 'Java_Empty_jdk', actualJavaVersion, 'x86');
const javaPathInstalled = path.join(
'toolcache',
'Java_Empty_jdk',
actualJavaVersion,
'x86'
);
let mockJavaBase: EmptyJavaBase;
@ -168,11 +255,16 @@ describe('setupJava', () => {
(toolname: string, javaVersion: string, architecture: string) => {
const semverVersion = new semver.Range(javaVersion);
if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) {
if (
path.basename(javaPath) !== architecture ||
!javaPath.includes(toolname)
) {
return '';
}
return semver.satisfies(installedJavaVersion, semverVersion) ? javaPath : '';
return semver.satisfies(installedJavaVersion, semverVersion)
? javaPath
: '';
}
);
@ -206,27 +298,46 @@ describe('setupJava', () => {
it.each([
[
{ version: '11', architecture: 'x86', packageType: 'jdk', checkLatest: false },
{ version: installedJavaVersion, path: javaPath }
{
version: '11',
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
},
{version: installedJavaVersion, path: javaPath}
],
[
{ version: '11.0', architecture: 'x86', packageType: 'jdk', checkLatest: false },
{ version: installedJavaVersion, path: javaPath }
{
version: '11.0',
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
},
{version: installedJavaVersion, path: javaPath}
],
[
{ version: '11.0.8', architecture: 'x86', packageType: 'jdk', checkLatest: false },
{ version: installedJavaVersion, path: javaPath }
{
version: '11.0.8',
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
},
{version: installedJavaVersion, path: javaPath}
],
[
{ version: '11', architecture: '', packageType: 'jdk', checkLatest: false },
{ version: installedJavaVersion, path: javaPath }
{version: '11', architecture: '', packageType: 'jdk', checkLatest: false},
{version: installedJavaVersion, path: javaPath}
]
])('should find java locally for %s', (input, expected) => {
])('should find java locally for %s', async (input, expected) => {
mockJavaBase = new EmptyJavaBase(input);
expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
expect(spyGetToolcachePath).toHaveBeenCalled();
expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved Java ${expected.version} from tool-cache`);
expect(spyCoreInfo).toHaveBeenCalledWith(`Setting Java ${expected.version} as the default`);
expect(spyCoreInfo).toHaveBeenCalledWith(
`Resolved Java ${expected.version} from tool-cache`
);
expect(spyCoreInfo).toHaveBeenCalledWith(
`Setting Java ${expected.version} as the default`
);
expect(spyCoreInfo).not.toHaveBeenCalledWith(
'Trying to resolve the latest version from remote'
);
@ -235,20 +346,47 @@ describe('setupJava', () => {
it.each([
[
{ version: '11', architecture: 'x86', packageType: 'jre', checkLatest: false },
{ path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x86'), version: '11.0.9' }
{
version: '11',
architecture: 'x86',
packageType: 'jre',
checkLatest: false
},
{
path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x86'),
version: '11.0.9'
}
],
[
{ version: '11', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{ path: path.join('toolcache', 'Java_Empty_jdk', '11.0.9', 'x64'), version: '11.0.9' }
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
{
path: path.join('toolcache', 'Java_Empty_jdk', '11.0.9', 'x64'),
version: '11.0.9'
}
],
[
{ version: '11', architecture: 'x64', packageType: 'jre', checkLatest: false },
{ path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x64'), version: '11.0.9' }
{
version: '11',
architecture: 'x64',
packageType: 'jre',
checkLatest: false
},
{
path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x64'),
version: '11.0.9'
}
],
[
{ version: '11', architecture: '', packageType: 'jre', checkLatest: false },
{ path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x86'), version: '11.0.9' }
{version: '11', architecture: '', packageType: 'jre', checkLatest: false},
{
path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x86'),
version: '11.0.9'
}
]
])('download java with configuration %s', async (input, expected) => {
mockJavaBase = new EmptyJavaBase(input);
@ -257,93 +395,176 @@ describe('setupJava', () => {
expect(spyCoreAddPath).toHaveBeenCalled();
expect(spyCoreExportVariable).toHaveBeenCalled();
expect(spyCoreExportVariable).toHaveBeenCalledWith(
`JAVA_HOME_${input.version}_${(input.architecture || 'x86').toLocaleUpperCase()}`,
`JAVA_HOME_${input.version}_${(
input.architecture || 'x86'
).toLocaleUpperCase()}`,
expected.path
);
expect(spyCoreSetOutput).toHaveBeenCalled();
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to resolve the latest version from remote');
expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved latest version as ${expected.version}`);
expect(spyCoreInfo).toHaveBeenCalledWith(
'Trying to resolve the latest version from remote'
);
expect(spyCoreInfo).toHaveBeenCalledWith(
`Resolved latest version as ${expected.version}`
);
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to download...');
expect(spyCoreInfo).toHaveBeenCalledWith(`Java ${expected.version} was downloaded`);
expect(spyCoreInfo).toHaveBeenCalledWith(`Setting Java ${expected.version} as the default`);
expect(spyCoreInfo).toHaveBeenCalledWith(
`Java ${expected.version} was downloaded`
);
expect(spyCoreInfo).toHaveBeenCalledWith(
`Setting Java ${expected.version} as the default`
);
});
it.each([
[
{ version: '11.0.9', architecture: 'x86', packageType: 'jdk', checkLatest: true },
{ version: '11.0.9', path: javaPathInstalled }
{
version: '11.0.9',
architecture: 'x86',
packageType: 'jdk',
checkLatest: true
},
{version: '11.0.9', path: javaPathInstalled}
],
[
{ version: '11.0.9', architecture: '', packageType: 'jdk', checkLatest: true },
{ version: '11.0.9', path: javaPathInstalled }
{
version: '11.0.9',
architecture: '',
packageType: 'jdk',
checkLatest: true
},
{version: '11.0.9', path: javaPathInstalled}
]
])('should check the latest java version for %s and resolve locally', async (input, expected) => {
mockJavaBase = new EmptyJavaBase(input);
mockJavaBase['findInToolcache'] = () => ({ version: '11.0.9', path: expected.path });
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to resolve the latest version from remote');
expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved latest version as ${expected.version}`);
expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved Java ${expected.version} from tool-cache`);
expect(spyCoreInfo).toHaveBeenCalledWith(`Setting Java ${expected.version} as the default`);
});
])(
'should check the latest java version for %s and resolve locally',
async (input, expected) => {
mockJavaBase = new EmptyJavaBase(input);
mockJavaBase['findInToolcache'] = () => ({
version: '11.0.9',
path: expected.path
});
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
expect(spyCoreInfo).toHaveBeenCalledWith(
'Trying to resolve the latest version from remote'
);
expect(spyCoreInfo).toHaveBeenCalledWith(
`Resolved latest version as ${expected.version}`
);
expect(spyCoreInfo).toHaveBeenCalledWith(
`Resolved Java ${expected.version} from tool-cache`
);
expect(spyCoreInfo).toHaveBeenCalledWith(
`Setting Java ${expected.version} as the default`
);
}
);
it.each([
[
{ version: '11', architecture: 'x86', packageType: 'jdk', checkLatest: true },
{ version: actualJavaVersion, path: javaPathInstalled }
{
version: '11',
architecture: 'x86',
packageType: 'jdk',
checkLatest: true
},
{version: actualJavaVersion, path: javaPathInstalled}
],
[
{ version: '11.0', architecture: 'x86', packageType: 'jdk', checkLatest: true },
{ version: actualJavaVersion, path: javaPathInstalled }
{
version: '11.0',
architecture: 'x86',
packageType: 'jdk',
checkLatest: true
},
{version: actualJavaVersion, path: javaPathInstalled}
],
[
{ version: '11.0.x', architecture: 'x86', packageType: 'jdk', checkLatest: true },
{ version: actualJavaVersion, path: javaPathInstalled }
{
version: '11.0.x',
architecture: 'x86',
packageType: 'jdk',
checkLatest: true
},
{version: actualJavaVersion, path: javaPathInstalled}
],
[
{ version: '11', architecture: '', packageType: 'jdk', checkLatest: true },
{ version: actualJavaVersion, path: javaPathInstalled }
{version: '11', architecture: '', packageType: 'jdk', checkLatest: true},
{version: actualJavaVersion, path: javaPathInstalled}
]
])('should check the latest java version for %s and download', async (input, expected) => {
mockJavaBase = new EmptyJavaBase(input);
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
expect(spyGetToolcachePath).toHaveBeenCalled();
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to resolve the latest version from remote');
expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved latest version as ${actualJavaVersion}`);
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to download...');
expect(spyCoreInfo).toHaveBeenCalledWith(`Java ${actualJavaVersion} was downloaded`);
expect(spyCoreInfo).toHaveBeenCalledWith(`Setting Java ${expected.version} as the default`);
});
])(
'should check the latest java version for %s and download',
async (input, expected) => {
mockJavaBase = new EmptyJavaBase(input);
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
expect(spyGetToolcachePath).toHaveBeenCalled();
expect(spyCoreInfo).toHaveBeenCalledWith(
'Trying to resolve the latest version from remote'
);
expect(spyCoreInfo).toHaveBeenCalledWith(
`Resolved latest version as ${actualJavaVersion}`
);
expect(spyCoreInfo).toHaveBeenCalledWith('Trying to download...');
expect(spyCoreInfo).toHaveBeenCalledWith(
`Java ${actualJavaVersion} was downloaded`
);
expect(spyCoreInfo).toHaveBeenCalledWith(
`Setting Java ${expected.version} as the default`
);
}
);
it.each([
[{ version: '15', architecture: 'x86', packageType: 'jre', checkLatest: false }],
[{ version: '11.0.7', architecture: 'x64', packageType: 'jre', checkLatest: false }]
])('should throw an error for Available version not found for %s', async input => {
mockJavaBase = new EmptyJavaBase(input);
await expect(mockJavaBase.setupJava()).rejects.toThrowError('Available version not found');
expect(spyTcFindAllVersions).toHaveBeenCalled();
expect(spyCoreAddPath).not.toHaveBeenCalled();
expect(spyCoreExportVariable).not.toHaveBeenCalled();
expect(spyCoreSetOutput).not.toHaveBeenCalled();
});
[
{
version: '15',
architecture: 'x86',
packageType: 'jre',
checkLatest: false
}
],
[
{
version: '11.0.7',
architecture: 'x64',
packageType: 'jre',
checkLatest: false
}
]
])(
'should throw an error for Available version not found for %s',
async input => {
mockJavaBase = new EmptyJavaBase(input);
await expect(mockJavaBase.setupJava()).rejects.toThrow(
'Available version not found'
);
expect(spyTcFindAllVersions).toHaveBeenCalled();
expect(spyCoreAddPath).not.toHaveBeenCalled();
expect(spyCoreExportVariable).not.toHaveBeenCalled();
expect(spyCoreSetOutput).not.toHaveBeenCalled();
}
);
});
describe('normalizeVersion', () => {
const DummyJavaBase = JavaBase as any;
it.each([
['11', { version: '11', stable: true }],
['11.0', { version: '11.0', stable: true }],
['11.0.10', { version: '11.0.10', stable: true }],
['11-ea', { version: '11', stable: false }],
['11.0.2-ea', { version: '11.0.2', stable: false }]
['11', {version: '11', stable: true}],
['11.0', {version: '11.0', stable: true}],
['11.0.10', {version: '11.0.10', stable: true}],
['11-ea', {version: '11', stable: false}],
['11.0.2-ea', {version: '11.0.2', stable: false}]
])('normalizeVersion from %s to %s', (input, expected) => {
expect(DummyJavaBase.prototype.normalizeVersion.call(null, input)).toEqual(expected);
expect(DummyJavaBase.prototype.normalizeVersion.call(null, input)).toEqual(
expected
);
});
it('normalizeVersion should throw an error for non semver', () => {
const version = '11g';
expect(DummyJavaBase.prototype.normalizeVersion.bind(null, version)).toThrowError(
expect(
DummyJavaBase.prototype.normalizeVersion.bind(null, version)
).toThrow(
`The string '${version}' is not valid SemVer notation for a Java version. Please check README file for code snippets and more detailed information`
);
});
@ -353,14 +574,14 @@ describe('getToolcacheVersionName', () => {
const DummyJavaBase = JavaBase as any;
it.each([
[{ version: '11', stable: true }, '11'],
[{ version: '11.0.2', stable: true }, '11.0.2'],
[{ version: '11.0.2+4', stable: true }, '11.0.2-4'],
[{ version: '11.0.2+4.1.2563234', stable: true }, '11.0.2-4.1.2563234'],
[{ version: '11.0', stable: false }, '11.0-ea'],
[{ version: '11.0.3', stable: false }, '11.0.3-ea'],
[{ version: '11.0.3+4', stable: false }, '11.0.3-ea.4'],
[{ version: '11.0.3+4.2.256', stable: false }, '11.0.3-ea.4.2.256']
[{version: '11', stable: true}, '11'],
[{version: '11.0.2', stable: true}, '11.0.2'],
[{version: '11.0.2+4', stable: true}, '11.0.2-4'],
[{version: '11.0.2+4.1.2563234', stable: true}, '11.0.2-4.1.2563234'],
[{version: '11.0', stable: false}, '11.0-ea'],
[{version: '11.0.3', stable: false}, '11.0.3-ea'],
[{version: '11.0.3+4', stable: false}, '11.0.3-ea.4'],
[{version: '11.0.3+4.2.256', stable: false}, '11.0.3-ea.4.2.256']
])('returns correct version name for %s', (input, expected) => {
const inputVersion = input.stable ? '11' : '11-ea';
const mockJavaBase = new EmptyJavaBase({

View File

@ -1,12 +1,12 @@
import { HttpClient } from '@actions/http-client';
import { JavaInstallerOptions } from '../../src/distributions/base-models';
import {HttpClient} from '@actions/http-client';
import {JavaInstallerOptions} from '../../src/distributions/base-models';
import { CorrettoDistribution } from '../../src/distributions/corretto/installer';
import {CorrettoDistribution} from '../../src/distributions/corretto/installer';
import * as util from '../../src/util';
import os from 'os';
import { isGeneratorFunction } from 'util/types';
import {isGeneratorFunction} from 'util/types';
const manifestData = require('../data/corretto.json') as [];
import manifestData from '../data/corretto.json';
describe('getAvailableVersions', () => {
let spyHttpClient: jest.SpyInstance;
@ -19,7 +19,10 @@ describe('getAvailableVersions', () => {
headers: {},
result: manifestData
});
spyGetDownloadArchiveExtension = jest.spyOn(util, 'getDownloadArchiveExtension');
spyGetDownloadArchiveExtension = jest.spyOn(
util,
'getDownloadArchiveExtension'
);
});
afterEach(() => {
@ -44,16 +47,66 @@ describe('getAvailableVersions', () => {
});
it.each([
[{ version: '16', architecture: 'x64', packageType: 'jdk', checkLatest: false }, 'macos', 6],
[{ version: '16', architecture: 'x86', packageType: 'jdk', checkLatest: false }, 'macos', 0],
[{ version: '16', architecture: 'x64', packageType: 'jre', checkLatest: false }, 'macos', 0],
[{ version: '16', architecture: 'x64', packageType: 'jdk', checkLatest: false }, 'linux', 6],
[
{ version: '18', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '16',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
'macos',
6
],
[
{
version: '16',
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
},
'macos',
0
],
[
{
version: '16',
architecture: 'x64',
packageType: 'jre',
checkLatest: false
},
'macos',
0
],
[
{
version: '16',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
'linux',
6
],
[
{
version: '18',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
'windows',
6
],
[{ version: '18', architecture: 'x64', packageType: 'jre', checkLatest: false }, 'windows', 1]
[
{
version: '18',
architecture: 'x64',
packageType: 'jre',
checkLatest: false
},
'windows',
1
]
])(
'fetch expected amount of available versions for %s',
async (
@ -66,7 +119,9 @@ describe('getAvailableVersions', () => {
const availableVersions = await distribution['getAvailableVersions']();
expect(availableVersions).not.toBeNull();
expect(availableVersions.length).toBe(expectedAmountOfAvailableVersions);
expect(availableVersions.length).toBe(
expectedAmountOfAvailableVersions
);
}
);
});
@ -95,7 +150,9 @@ describe('getAvailableVersions', () => {
});
mockPlatform(distribution, platform);
const availableVersion = await distribution['findPackageForDownload'](version);
const availableVersion = await distribution['findPackageForDownload'](
version
);
expect(availableVersion).not.toBeNull();
expect(availableVersion.url).toBe(expectedLink);
});
@ -110,9 +167,9 @@ describe('getAvailableVersions', () => {
});
mockPlatform(distribution, 'linux');
await expect(distribution['findPackageForDownload'](version)).rejects.toThrowError(
'Early access versions are not supported'
);
await expect(
distribution['findPackageForDownload'](version)
).rejects.toThrow('Early access versions are not supported');
});
it('with non major version expect to throw not supported error', async () => {
@ -125,9 +182,9 @@ describe('getAvailableVersions', () => {
});
mockPlatform(distribution, 'linux');
await expect(distribution['findPackageForDownload'](version)).rejects.toThrowError(
'Only major versions are supported'
);
await expect(
distribution['findPackageForDownload'](version)
).rejects.toThrow('Only major versions are supported');
});
it('with unfound version throw could not find error', async () => {
@ -140,9 +197,9 @@ describe('getAvailableVersions', () => {
});
mockPlatform(distribution, 'linux');
await expect(distribution['findPackageForDownload'](version)).rejects.toThrowError(
"Could not find satisfied version for SemVer '4'"
);
await expect(
distribution['findPackageForDownload'](version)
).rejects.toThrow("Could not find satisfied version for SemVer '4'");
});
it.each([
@ -166,14 +223,19 @@ describe('getAvailableVersions', () => {
const expectedLink = `https://corretto.aws/downloads/resources/17.0.2.8.1/amazon-corretto-17.0.2.8.1-macosx-${distroArch}.tar.gz`;
const availableVersion = await distribution['findPackageForDownload'](version);
const availableVersion = await distribution['findPackageForDownload'](
version
);
expect(availableVersion).not.toBeNull();
expect(availableVersion.url).toBe(expectedLink);
}
);
});
const mockPlatform = (distribution: CorrettoDistribution, platform: string) => {
const mockPlatform = (
distribution: CorrettoDistribution,
platform: string
) => {
distribution['getPlatformOption'] = () => platform;
const mockedExtension = platform === 'windows' ? 'zip' : 'tar.gz';
spyGetDownloadArchiveExtension.mockReturnValue(mockedExtension);

View File

@ -1,9 +1,12 @@
import { LibericaDistributions } from '../../src/distributions/liberica/installer';
import { ArchitectureOptions, LibericaVersion } from '../../src/distributions/liberica/models';
import { HttpClient } from '@actions/http-client';
import {LibericaDistributions} from '../../src/distributions/liberica/installer';
import {
ArchitectureOptions,
LibericaVersion
} from '../../src/distributions/liberica/models';
import {HttpClient} from '@actions/http-client';
import os from 'os';
const manifestData = require('../data/liberica.json') as LibericaVersion[];
import manifestData from '../data/liberica.json';
describe('getAvailableVersions', () => {
let spyHttpClient: jest.SpyInstance;
@ -13,7 +16,7 @@ describe('getAvailableVersions', () => {
spyHttpClient.mockReturnValue({
statusCode: 200,
headers: {},
result: manifestData
result: manifestData as LibericaVersion[]
});
});
@ -25,27 +28,57 @@ describe('getAvailableVersions', () => {
it.each([
[
{ version: '11.x', architecture: 'x86', packageType: 'jdk', checkLatest: false },
{
version: '11.x',
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
},
'bundle-type=jdk&bitness=32&arch=x86&build-type=all'
],
[
{ version: '11-ea', architecture: 'x86', packageType: 'jdk', checkLatest: false },
{
version: '11-ea',
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
},
'bundle-type=jdk&bitness=32&arch=x86&build-type=ea'
],
[
{ version: '16.0.2', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '16.0.2',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
'bundle-type=jdk&bitness=64&arch=x86&build-type=all'
],
[
{ version: '16.0.2', architecture: 'x64', packageType: 'jre', checkLatest: false },
{
version: '16.0.2',
architecture: 'x64',
packageType: 'jre',
checkLatest: false
},
'bundle-type=jre&bitness=64&arch=x86&build-type=all'
],
[
{ version: '8', architecture: 'armv7', packageType: 'jdk+fx', checkLatest: false },
{
version: '8',
architecture: 'armv7',
packageType: 'jdk+fx',
checkLatest: false
},
'bundle-type=jdk-full&bitness=32&arch=arm&build-type=all'
],
[
{ version: '8', architecture: 'aarch64', packageType: 'jre+fx', checkLatest: false },
{
version: '8',
architecture: 'aarch64',
packageType: 'jre+fx',
checkLatest: false
},
'bundle-type=jre-full&bitness=64&arch=arm&build-type=all'
]
])('build correct url for %s -> %s', async (input, urlParams) => {
@ -67,8 +100,8 @@ describe('getAvailableVersions', () => {
arch: string;
};
it.each([
['amd64', { bitness: '64', arch: 'x86' }],
['arm64', { bitness: '64', arch: 'arm' }]
['amd64', {bitness: '64', arch: 'x86'}],
['arm64', {bitness: '64', arch: 'arm'}]
])(
'defaults to os.arch(): %s mapped to distro arch: %s',
async (osArch: string, distroArch: DistroArch) => {
@ -109,21 +142,24 @@ describe('getAvailableVersions', () => {
describe('getArchitectureOptions', () => {
it.each([
['x86', { bitness: '32', arch: 'x86' }],
['x64', { bitness: '64', arch: 'x86' }],
['armv7', { bitness: '32', arch: 'arm' }],
['aarch64', { bitness: '64', arch: 'arm' }],
['ppc64le', { bitness: '64', arch: 'ppc' }]
] as [string, ArchitectureOptions][])('parse architecture %s -> %s', (input, expected) => {
const distributions = new LibericaDistributions({
architecture: input,
checkLatest: false,
packageType: '',
version: ''
});
['x86', {bitness: '32', arch: 'x86'}],
['x64', {bitness: '64', arch: 'x86'}],
['armv7', {bitness: '32', arch: 'arm'}],
['aarch64', {bitness: '64', arch: 'arm'}],
['ppc64le', {bitness: '64', arch: 'ppc'}]
] as [string, ArchitectureOptions][])(
'parse architecture %s -> %s',
(input, expected) => {
const distributions = new LibericaDistributions({
architecture: input,
checkLatest: false,
packageType: '',
version: ''
});
expect(distributions['getArchitectureOptions']()).toEqual(expected);
});
expect(distributions['getArchitectureOptions']()).toEqual(expected);
}
);
it.each(['armv6', 's390x'])('not support architecture %s', input => {
const distributions = new LibericaDistributions({
@ -199,9 +235,9 @@ describe('getPlatformOption', () => {
it.each(['aix', 'android', 'freebsd', 'openbsd', 'netbsd'])(
'not support os version %s',
input => {
expect(() => distributions['getPlatformOption'](input as NodeJS.Platform)).toThrow(
/Platform '\w+' is not supported\. Supported platforms: .+/
);
expect(() =>
distributions['getPlatformOption'](input as NodeJS.Platform)
).toThrow(/Platform '\w+' is not supported\. Supported platforms: .+/);
}
);
});
@ -215,9 +251,33 @@ describe('convertVersionToSemver', () => {
});
it.each([
[{ featureVersion: 11, interimVersion: 0, updateVersion: 12, buildVersion: 7 }, '11.0.12+7'],
[{ featureVersion: 11, interimVersion: 0, updateVersion: 12, buildVersion: 0 }, '11.0.12'],
[{ featureVersion: 11, interimVersion: 0, updateVersion: 0, buildVersion: 13 }, '11.0.0+13']
[
{
featureVersion: 11,
interimVersion: 0,
updateVersion: 12,
buildVersion: 7
},
'11.0.12+7'
],
[
{
featureVersion: 11,
interimVersion: 0,
updateVersion: 12,
buildVersion: 0
},
'11.0.12'
],
[
{
featureVersion: 11,
interimVersion: 0,
updateVersion: 0,
buildVersion: 13
},
'11.0.0+13'
]
])('%s -> %s', (input, expected) => {
const actual = distributions['convertVersionToSemver']({
downloadUrl: '',

View File

@ -7,7 +7,7 @@ import path from 'path';
import * as semver from 'semver';
import * as util from '../../src/util';
import { LocalDistribution } from '../../src/distributions/local/installer';
import {LocalDistribution} from '../../src/distributions/local/installer';
describe('setupJava', () => {
const actualJavaVersion = '11.1.10';
@ -27,7 +27,7 @@ describe('setupJava', () => {
let spyFsReadDir: jest.SpyInstance;
let spyUtilsExtractJdkFile: jest.SpyInstance;
let spyPathResolve: jest.SpyInstance;
let expectedJdkFile = 'JavaLocalJdkFile';
const expectedJdkFile = 'JavaLocalJdkFile';
beforeEach(() => {
spyGetToolcachePath = jest.spyOn(util, 'getToolcachePath');
@ -35,18 +35,27 @@ describe('setupJava', () => {
(toolname: string, javaVersion: string, architecture: string) => {
const semverVersion = new semver.Range(javaVersion);
if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) {
if (
path.basename(javaPath) !== architecture ||
!javaPath.includes(toolname)
) {
return '';
}
return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : '';
return semver.satisfies(actualJavaVersion, semverVersion)
? javaPath
: '';
}
);
spyTcCacheDir = jest.spyOn(tc, 'cacheDir');
spyTcCacheDir.mockImplementation(
(archivePath: string, toolcacheFolderName: string, version: string, architecture: string) =>
path.join(toolcacheFolderName, version, architecture)
(
archivePath: string,
toolcacheFolderName: string,
version: string,
architecture: string
) => path.join(toolcacheFolderName, version, architecture)
);
spyTcFindAllVersions = jest.spyOn(tc, 'findAllVersions');
@ -74,7 +83,7 @@ describe('setupJava', () => {
spyFsStat = jest.spyOn(fs, 'statSync');
spyFsStat.mockImplementation((file: string) => {
return { isFile: () => file === expectedJdkFile };
return {isFile: () => file === expectedJdkFile};
});
// Spy on util methods
@ -108,7 +117,9 @@ describe('setupJava', () => {
mockJavaBase = new LocalDistribution(inputs, jdkFile);
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
expect(spyGetToolcachePath).toHaveBeenCalled();
expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved Java ${actualJavaVersion} from tool-cache`);
expect(spyCoreInfo).toHaveBeenCalledWith(
`Resolved Java ${actualJavaVersion} from tool-cache`
);
expect(spyCoreInfo).not.toHaveBeenCalledWith(
`Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...`
);
@ -130,7 +141,9 @@ describe('setupJava', () => {
mockJavaBase = new LocalDistribution(inputs, jdkFile);
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
expect(spyGetToolcachePath).toHaveBeenCalled();
expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved Java ${actualJavaVersion} from tool-cache`);
expect(spyCoreInfo).toHaveBeenCalledWith(
`Resolved Java ${actualJavaVersion} from tool-cache`
);
expect(spyCoreInfo).not.toHaveBeenCalledWith(
`Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...`
);
@ -155,7 +168,9 @@ describe('setupJava', () => {
expect(spyCoreInfo).not.toHaveBeenCalledWith(
`Resolved Java ${actualJavaVersion} from tool-cache`
);
expect(spyCoreInfo).toHaveBeenCalledWith(`Extracting Java from '${jdkFile}'`);
expect(spyCoreInfo).toHaveBeenCalledWith(
`Extracting Java from '${jdkFile}'`
);
expect(spyCoreInfo).toHaveBeenCalledWith(
`Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...`
);
@ -171,19 +186,29 @@ describe('setupJava', () => {
const jdkFile = 'not_existing_one';
const expected = {
javaVersion: '11.0.289',
javaPath: path.join('Java_jdkfile_jdk', inputs.version, inputs.architecture)
javaPath: path.join(
'Java_jdkfile_jdk',
inputs.version,
inputs.architecture
)
};
mockJavaBase = new LocalDistribution(inputs, jdkFile);
expected.javaPath = path.join('Java_jdkfile_jdk', inputs.version, inputs.architecture);
await expect(mockJavaBase.setupJava()).rejects.toThrowError(
expected.javaPath = path.join(
'Java_jdkfile_jdk',
inputs.version,
inputs.architecture
);
await expect(mockJavaBase.setupJava()).rejects.toThrow(
"JDK file was not found in path 'not_existing_one'"
);
expect(spyTcFindAllVersions).toHaveBeenCalled();
expect(spyCoreInfo).not.toHaveBeenCalledWith(
`Resolved Java ${actualJavaVersion} from tool-cache`
);
expect(spyCoreInfo).not.toHaveBeenCalledWith(`Extracting Java from '${jdkFile}'`);
expect(spyCoreInfo).not.toHaveBeenCalledWith(
`Extracting Java from '${jdkFile}'`
);
expect(spyCoreInfo).toHaveBeenCalledWith(
`Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...`
);
@ -191,26 +216,46 @@ describe('setupJava', () => {
it.each([
[
{ version: '8.0.289', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '8.0.289',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
'otherJdkFile'
],
[
{ version: '11.0.289', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '11.0.289',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
'otherJdkFile'
],
[
{ version: '12.0.289', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '12.0.289',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
'otherJdkFile'
],
[
{ version: '11.1.11', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '11.1.11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
'not_existing_one'
]
])(
`Throw an error if jdkfile has wrong path, inputs %s, jdkfile %s, real name ${expectedJdkFile}`,
async (inputs, jdkFile) => {
mockJavaBase = new LocalDistribution(inputs, jdkFile);
await expect(mockJavaBase.setupJava()).rejects.toThrowError(
await expect(mockJavaBase.setupJava()).rejects.toThrow(
/JDK file was not found in path */
);
expect(spyTcFindAllVersions).toHaveBeenCalled();
@ -218,18 +263,41 @@ describe('setupJava', () => {
);
it.each([
[{ version: '8.0.289', architecture: 'x64', packageType: 'jdk', checkLatest: false }, ''],
[
{ version: '7.0.289', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '8.0.289',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
''
],
[
{
version: '7.0.289',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
undefined
],
[
{ version: '11.0.289', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '11.0.289',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
undefined
]
])('Throw an error if jdkfile is not specified, inputs %s', async (inputs, jdkFile) => {
mockJavaBase = new LocalDistribution(inputs, jdkFile);
await expect(mockJavaBase.setupJava()).rejects.toThrowError("'jdkFile' is not specified");
expect(spyTcFindAllVersions).toHaveBeenCalled();
});
])(
'Throw an error if jdkfile is not specified, inputs %s',
async (inputs, jdkFile) => {
mockJavaBase = new LocalDistribution(inputs, jdkFile);
await expect(mockJavaBase.setupJava()).rejects.toThrow(
"'jdkFile' is not specified"
);
expect(spyTcFindAllVersions).toHaveBeenCalled();
}
);
});

View File

@ -1,4 +1,4 @@
import { MicrosoftDistributions } from '../../src/distributions/microsoft/installer';
import {MicrosoftDistributions} from '../../src/distributions/microsoft/installer';
import os from 'os';
import data from '../../src/distributions/microsoft/microsoft-openjdk-versions.json';
import * as httpm from '@actions/http-client';
@ -73,7 +73,9 @@ describe('findPackageForDownload', () => {
archive = 'tar.gz';
break;
}
const url = expectedUrl.replace('{{OS_TYPE}}', os).replace('{{ARCHIVE_TYPE}}', archive);
const url = expectedUrl
.replace('{{OS_TYPE}}', os)
.replace('{{ARCHIVE_TYPE}}', archive);
expect(result.url).toBe(url);
});

View File

@ -1,7 +1,7 @@
import { OracleDistribution } from '../../src/distributions/oracle/installer';
import {OracleDistribution} from '../../src/distributions/oracle/installer';
import os from 'os';
import * as core from '@actions/core';
import { getDownloadArchiveExtension } from '../../src/util';
import {getDownloadArchiveExtension} from '../../src/util';
describe('findPackageForDownload', () => {
let distribution: OracleDistribution;
@ -50,7 +50,9 @@ describe('findPackageForDownload', () => {
expect(result.version).toBe(expectedVersion);
const osType = distribution.getPlatform();
const archiveType = getDownloadArchiveExtension();
const url = expectedUrl.replace('{{OS_TYPE}}', osType).replace('{{ARCHIVE_TYPE}}', archiveType);
const url = expectedUrl
.replace('{{OS_TYPE}}', osType)
.replace('{{ARCHIVE_TYPE}}', archiveType);
expect(result.url).toBe(url);
});

View File

@ -1,12 +1,12 @@
import { HttpClient } from '@actions/http-client';
import {HttpClient} from '@actions/http-client';
import os from 'os';
import {
TemurinDistribution,
TemurinImplementation
} from '../../src/distributions/temurin/installer';
import { JavaInstallerOptions } from '../../src/distributions/base-models';
import {JavaInstallerOptions} from '../../src/distributions/base-models';
let manifestData = require('../data/temurin.json') as [];
import manifestData from '../data/temurin.json';
describe('getAvailableVersions', () => {
let spyHttpClient: jest.SpyInstance;
@ -28,22 +28,42 @@ describe('getAvailableVersions', () => {
it.each([
[
{ version: '16', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '16',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
TemurinImplementation.Hotspot,
'os=mac&architecture=x64&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=0'
],
[
{ version: '16', architecture: 'x86', packageType: 'jdk', checkLatest: false },
{
version: '16',
architecture: 'x86',
packageType: 'jdk',
checkLatest: false
},
TemurinImplementation.Hotspot,
'os=mac&architecture=x86&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=0'
],
[
{ version: '16', architecture: 'x64', packageType: 'jre', checkLatest: false },
{
version: '16',
architecture: 'x64',
packageType: 'jre',
checkLatest: false
},
TemurinImplementation.Hotspot,
'os=mac&architecture=x64&image_type=jre&release_type=ga&jvm_impl=hotspot&page_size=20&page=0'
],
[
{ version: '16-ea', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '16-ea',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
TemurinImplementation.Hotspot,
'os=mac&architecture=x64&image_type=jdk&release_type=ea&jvm_impl=hotspot&page_size=20&page=0'
]
@ -55,7 +75,8 @@ describe('getAvailableVersions', () => {
expectedParameters
) => {
const distribution = new TemurinDistribution(installerOptions, impl);
const baseUrl = 'https://api.adoptium.net/v3/assets/version/%5B1.0,100.0%5D';
const baseUrl =
'https://api.adoptium.net/v3/assets/version/%5B1.0,100.0%5D';
const expectedUrl = `${baseUrl}?project=jdk&vendor=adoptium&heap_size=normal&sort_method=DEFAULT&sort_order=DESC&${expectedParameters}`;
distribution['getPlatformOption'] = () => 'mac';
@ -72,12 +93,12 @@ describe('getAvailableVersions', () => {
.mockReturnValueOnce({
statusCode: 200,
headers: {},
result: manifestData
result: manifestData as any
})
.mockReturnValueOnce({
statusCode: 200,
headers: {},
result: manifestData
result: manifestData as any
})
.mockReturnValueOnce({
statusCode: 200,
@ -86,7 +107,12 @@ describe('getAvailableVersions', () => {
});
const distribution = new TemurinDistribution(
{ version: '8', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '8',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
TemurinImplementation.Hotspot
);
const availableVersions = await distribution['getAvailableVersions']();
@ -101,7 +127,12 @@ describe('getAvailableVersions', () => {
'find right toolchain folder',
(impl: TemurinImplementation, packageType: string, expected: string) => {
const distribution = new TemurinDistribution(
{ version: '8', architecture: 'x64', packageType: packageType, checkLatest: false },
{
version: '8',
architecture: 'x64',
packageType: packageType,
checkLatest: false
},
impl
);
@ -127,8 +158,12 @@ describe('getAvailableVersions', () => {
const expectedParameters = `os=mac&architecture=${distroArch}&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=0`;
const distribution = new TemurinDistribution(installerOptions, TemurinImplementation.Hotspot);
const baseUrl = 'https://api.adoptium.net/v3/assets/version/%5B1.0,100.0%5D';
const distribution = new TemurinDistribution(
installerOptions,
TemurinImplementation.Hotspot
);
const baseUrl =
'https://api.adoptium.net/v3/assets/version/%5B1.0,100.0%5D';
const expectedUrl = `${baseUrl}?project=jdk&vendor=adoptium&heap_size=normal&sort_method=DEFAULT&sort_order=DESC&${expectedParameters}`;
distribution['getPlatformOption'] = () => 'mac';
@ -150,43 +185,63 @@ describe('findPackageForDownload', () => {
['x', '16.0.2+7']
])('version is resolved correctly %s -> %s', async (input, expected) => {
const distribution = new TemurinDistribution(
{ version: '8', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '8',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
TemurinImplementation.Hotspot
);
distribution['getAvailableVersions'] = async () => manifestData;
distribution['getAvailableVersions'] = async () => manifestData as any;
const resolvedVersion = await distribution['findPackageForDownload'](input);
expect(resolvedVersion.version).toBe(expected);
});
it('version is found but binaries list is empty', async () => {
const distribution = new TemurinDistribution(
{ version: '9.0.8', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '9.0.8',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
TemurinImplementation.Hotspot
);
distribution['getAvailableVersions'] = async () => manifestData;
await expect(distribution['findPackageForDownload']('9.0.8')).rejects.toThrowError(
/Could not find satisfied version for SemVer */
);
distribution['getAvailableVersions'] = async () => manifestData as any;
await expect(
distribution['findPackageForDownload']('9.0.8')
).rejects.toThrow(/Could not find satisfied version for SemVer */);
});
it('version is not found', async () => {
const distribution = new TemurinDistribution(
{ version: '7.x', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '7.x',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
TemurinImplementation.Hotspot
);
distribution['getAvailableVersions'] = async () => manifestData;
await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrowError(
distribution['getAvailableVersions'] = async () => manifestData as any;
await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrow(
/Could not find satisfied version for SemVer */
);
});
it('version list is empty', async () => {
const distribution = new TemurinDistribution(
{ version: '8', architecture: 'x64', packageType: 'jdk', checkLatest: false },
{
version: '8',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
TemurinImplementation.Hotspot
);
distribution['getAvailableVersions'] = async () => [];
await expect(distribution['findPackageForDownload']('8')).rejects.toThrowError(
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow(
/Could not find satisfied version for SemVer */
);
});

View File

@ -1,11 +1,11 @@
import { HttpClient } from '@actions/http-client';
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 {ZuluDistribution} from '../../src/distributions/zulu/installer';
import {IZuluVersions} from '../../src/distributions/zulu/models';
import * as utils from '../../src/util';
import os from 'os';
const manifestData = require('../data/zulu-releases-default.json') as [];
import manifestData from '../data/zulu-releases-default.json';
describe('getAvailableVersions', () => {
let spyHttpClient: jest.SpyInstance;
@ -19,7 +19,10 @@ describe('getAvailableVersions', () => {
result: manifestData as IZuluVersions[]
});
spyUtilGetDownloadArchiveExtension = jest.spyOn(utils, 'getDownloadArchiveExtension');
spyUtilGetDownloadArchiveExtension = jest.spyOn(
utils,
'getDownloadArchiveExtension'
);
spyUtilGetDownloadArchiveExtension.mockReturnValue('tar.gz');
});
@ -31,35 +34,75 @@ describe('getAvailableVersions', () => {
it.each([
[
{ version: '11', architecture: 'x86', packageType: 'jdk', checkLatest: false },
{
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 },
{
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 },
{
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 },
{
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 },
{
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 },
{
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'
],
[
{ version: '11', architecture: 'arm64', packageType: 'jdk', checkLatest: false },
{
version: '11',
architecture: 'arm64',
packageType: 'jdk',
checkLatest: false
},
'?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=arm&hw_bitness=64&release_status=ga'
],
[
{ version: '11', architecture: 'arm', packageType: 'jdk', checkLatest: false },
{
version: '11',
architecture: 'arm',
packageType: 'jdk',
checkLatest: false
},
'?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=arm&hw_bitness=&release_status=ga'
]
])('build correct url for %s -> %s', async (input, parsedUrl) => {
@ -78,8 +121,8 @@ describe('getAvailableVersions', () => {
arch: string;
};
it.each([
['amd64', { bitness: '64', arch: 'x86' }],
['arm64', { bitness: '64', arch: 'arm' }]
['amd64', {bitness: '64', arch: 'x86'}],
['arm64', {bitness: '64', arch: 'arm'}]
])(
'defaults to os.arch(): %s mapped to distro arch: %s',
async (osArch: string, distroArch: DistroArch) => {
@ -115,10 +158,10 @@ describe('getAvailableVersions', () => {
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: '' }]
[{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',
@ -151,7 +194,9 @@ describe('findPackageForDownload', () => {
checkLatest: false
});
distribution['getAvailableVersions'] = async () => manifestData;
const result = await distribution['findPackageForDownload'](distribution['version']);
const result = await distribution['findPackageForDownload'](
distribution['version']
);
expect(result.version).toBe(expected);
});
@ -179,7 +224,7 @@ describe('findPackageForDownload', () => {
distribution['getAvailableVersions'] = async () => manifestData;
await expect(
distribution['findPackageForDownload'](distribution['version'])
).rejects.toThrowError(/Could not find satisfied version for semver */);
).rejects.toThrow(/Could not find satisfied version for semver */);
});
});