mirror of
https://github.com/actions/setup-java.git
synced 2025-04-20 18:06:45 +00:00
pull latest main
This commit is contained in:
parent
793a1df84f
commit
e9a0f2c685
8 changed files with 172 additions and 92 deletions
|
@ -96,7 +96,10 @@ describe('findPackageForDownload', () => {
|
|||
['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', '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']
|
||||
])('version is resolved correctly %s -> %s', async (input, expected) => {
|
||||
const distribution = new AdoptiumDistribution({
|
||||
version: '11',
|
||||
|
@ -104,7 +107,7 @@ describe('findPackageForDownload', () => {
|
|||
packageType: 'jdk'
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => manifestData;
|
||||
const resolvedVersion = await distribution['findPackageForDownload'](new semver.Range(input));
|
||||
const resolvedVersion = await distribution['findPackageForDownload'](input);
|
||||
expect(resolvedVersion.version).toBe(expected);
|
||||
});
|
||||
|
||||
|
@ -115,9 +118,9 @@ describe('findPackageForDownload', () => {
|
|||
packageType: 'jdk'
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => manifestData;
|
||||
await expect(
|
||||
distribution['findPackageForDownload'](new semver.Range('9.0.8'))
|
||||
).rejects.toThrowError(/Could not find satisfied version for SemVer */);
|
||||
await expect(distribution['findPackageForDownload']('9.0.8')).rejects.toThrowError(
|
||||
/Could not find satisfied version for SemVer */
|
||||
);
|
||||
});
|
||||
|
||||
it('version is not found', async () => {
|
||||
|
@ -127,9 +130,9 @@ describe('findPackageForDownload', () => {
|
|||
packageType: 'jdk'
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => manifestData;
|
||||
await expect(
|
||||
distribution['findPackageForDownload'](new semver.Range('7.x'))
|
||||
).rejects.toThrowError(/Could not find satisfied version for SemVer */);
|
||||
await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrowError(
|
||||
/Could not find satisfied version for SemVer */
|
||||
);
|
||||
});
|
||||
|
||||
it('version list is empty', async () => {
|
||||
|
@ -139,8 +142,8 @@ describe('findPackageForDownload', () => {
|
|||
packageType: 'jdk'
|
||||
});
|
||||
distribution['getAvailableVersions'] = async () => [];
|
||||
await expect(
|
||||
distribution['findPackageForDownload'](new semver.Range('11'))
|
||||
).rejects.toThrowError(/Could not find satisfied version for SemVer */);
|
||||
await expect(distribution['findPackageForDownload']('11')).rejects.toThrowError(
|
||||
/Could not find satisfied version for SemVer */
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import * as tc from '@actions/tool-cache';
|
||||
import * as core from '@actions/core';
|
||||
import * as util from '../../src/util';
|
||||
|
||||
import path from 'path';
|
||||
import * as semver from 'semver';
|
||||
|
@ -23,7 +24,7 @@ class EmptyJavaBase extends JavaBase {
|
|||
};
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(range: semver.Range): Promise<JavaDownloadRelease> {
|
||||
protected async findPackageForDownload(range: string): Promise<JavaDownloadRelease> {
|
||||
const availableVersion = '11.0.8';
|
||||
if (!semver.satisfies(availableVersion, range)) {
|
||||
throw new Error('Available version not found');
|
||||
|
@ -41,11 +42,11 @@ describe('findInToolcache', () => {
|
|||
const javaPath = path.join('Java_Empty_jdk', actualJavaVersion, 'x64');
|
||||
|
||||
let mockJavaBase: EmptyJavaBase;
|
||||
let spyTcFind: jest.SpyInstance;
|
||||
let spyGetToolcachePath: jest.SpyInstance;
|
||||
let spyTcFindAllVersions: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyTcFind = jest.spyOn(tc, 'find');
|
||||
spyGetToolcachePath = jest.spyOn(util, 'getToolcachePath');
|
||||
spyTcFindAllVersions = jest.spyOn(tc, 'findAllVersions');
|
||||
});
|
||||
|
||||
|
@ -74,15 +75,17 @@ describe('findInToolcache', () => {
|
|||
[{ version: '11', arch: 'x86', packageType: 'jre' }, null]
|
||||
])(`should find java for path %s -> %s`, (input, expected) => {
|
||||
spyTcFindAllVersions.mockReturnValue([actualJavaVersion]);
|
||||
spyTcFind.mockImplementation((toolname: string, javaVersion: string, architecture: string) => {
|
||||
const semverVersion = new semver.Range(javaVersion);
|
||||
spyGetToolcachePath.mockImplementation(
|
||||
(toolname: string, javaVersion: string, architecture: string) => {
|
||||
const semverVersion = new semver.Range(javaVersion);
|
||||
|
||||
if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) {
|
||||
return '';
|
||||
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);
|
||||
expect(mockJavaBase['findInToolcache']()).toEqual(expected);
|
||||
});
|
||||
|
@ -108,7 +111,7 @@ describe('findInToolcache', () => {
|
|||
'11.3.2-ea',
|
||||
'11.0.1'
|
||||
]);
|
||||
spyTcFind.mockImplementation(
|
||||
spyGetToolcachePath.mockImplementation(
|
||||
(toolname: string, javaVersion: string, architecture: string) =>
|
||||
`/hostedtoolcache/${toolname}/${javaVersion}/${architecture}`
|
||||
);
|
||||
|
@ -124,7 +127,7 @@ describe('setupJava', () => {
|
|||
|
||||
let mockJavaBase: EmptyJavaBase;
|
||||
|
||||
let spyTcFind: jest.SpyInstance;
|
||||
let spyGetToolcachePath: jest.SpyInstance;
|
||||
let spyTcFindAllVersions: jest.SpyInstance;
|
||||
let spyCoreDebug: jest.SpyInstance;
|
||||
let spyCoreInfo: jest.SpyInstance;
|
||||
|
@ -133,16 +136,18 @@ describe('setupJava', () => {
|
|||
let spyCoreSetOutput: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyTcFind = jest.spyOn(tc, 'find');
|
||||
spyTcFind.mockImplementation((toolname: string, javaVersion: string, architecture: string) => {
|
||||
const semverVersion = new semver.Range(javaVersion);
|
||||
spyGetToolcachePath = jest.spyOn(util, 'getToolcachePath');
|
||||
spyGetToolcachePath.mockImplementation(
|
||||
(toolname: string, javaVersion: string, architecture: string) => {
|
||||
const semverVersion = new semver.Range(javaVersion);
|
||||
|
||||
if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) {
|
||||
return '';
|
||||
if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : '';
|
||||
}
|
||||
|
||||
return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : '';
|
||||
});
|
||||
);
|
||||
|
||||
spyTcFindAllVersions = jest.spyOn(tc, 'findAllVersions');
|
||||
spyTcFindAllVersions.mockReturnValue([actualJavaVersion]);
|
||||
|
@ -186,7 +191,7 @@ describe('setupJava', () => {
|
|||
])('should find java locally for %s', (input, expected) => {
|
||||
mockJavaBase = new EmptyJavaBase(input);
|
||||
expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
|
||||
expect(spyTcFind).toHaveBeenCalled();
|
||||
expect(spyGetToolcachePath).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each([
|
||||
|
@ -205,7 +210,7 @@ describe('setupJava', () => {
|
|||
])('download java with configuration %s', async (input, expected) => {
|
||||
mockJavaBase = new EmptyJavaBase(input);
|
||||
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
|
||||
expect(spyTcFind).toHaveBeenCalled();
|
||||
expect(spyGetToolcachePath).toHaveBeenCalled();
|
||||
expect(spyCoreAddPath).toHaveBeenCalled();
|
||||
expect(spyCoreExportVariable).toHaveBeenCalled();
|
||||
expect(spyCoreSetOutput).toHaveBeenCalled();
|
||||
|
@ -228,11 +233,11 @@ describe('normalizeVersion', () => {
|
|||
const DummyJavaBase = JavaBase as any;
|
||||
|
||||
it.each([
|
||||
['11', { version: new semver.Range('11'), stable: true }],
|
||||
['11.0', { version: new semver.Range('11.0'), stable: true }],
|
||||
['11.0.10', { version: new semver.Range('11.0.10'), stable: true }],
|
||||
['11-ea', { version: new semver.Range('11'), stable: false }],
|
||||
['11.0.2-ea', { version: new semver.Range('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);
|
||||
});
|
||||
|
|
|
@ -5,7 +5,7 @@ import * as core from '@actions/core';
|
|||
|
||||
import path from 'path';
|
||||
import * as semver from 'semver';
|
||||
import * as utils from '../../src/util';
|
||||
import * as util from '../../src/util';
|
||||
|
||||
import { LocalDistribution } from '../../src/distributions/local/installer';
|
||||
|
||||
|
@ -15,7 +15,7 @@ describe('setupJava', () => {
|
|||
|
||||
let mockJavaBase: LocalDistribution;
|
||||
|
||||
let spyTcFind: jest.SpyInstance;
|
||||
let spyGetToolcachePath: jest.SpyInstance;
|
||||
let spyTcCacheDir: jest.SpyInstance;
|
||||
let spyTcFindAllVersions: jest.SpyInstance;
|
||||
let spyCoreDebug: jest.SpyInstance;
|
||||
|
@ -30,16 +30,18 @@ describe('setupJava', () => {
|
|||
let expectedJdkFile = 'JavaLocalJdkFile';
|
||||
|
||||
beforeEach(() => {
|
||||
spyTcFind = jest.spyOn(tc, 'find');
|
||||
spyTcFind.mockImplementation((toolname: string, javaVersion: string, architecture: string) => {
|
||||
const semverVersion = new semver.Range(javaVersion);
|
||||
spyGetToolcachePath = jest.spyOn(util, 'getToolcachePath');
|
||||
spyGetToolcachePath.mockImplementation(
|
||||
(toolname: string, javaVersion: string, architecture: string) => {
|
||||
const semverVersion = new semver.Range(javaVersion);
|
||||
|
||||
if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) {
|
||||
return '';
|
||||
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(
|
||||
|
@ -76,7 +78,7 @@ describe('setupJava', () => {
|
|||
});
|
||||
|
||||
// Spy on util methods
|
||||
spyUtilsExtractJdkFile = jest.spyOn(utils, 'extractJdkFile');
|
||||
spyUtilsExtractJdkFile = jest.spyOn(util, 'extractJdkFile');
|
||||
spyUtilsExtractJdkFile.mockImplementation(() => 'some/random/path/');
|
||||
|
||||
// Spy on path methods
|
||||
|
@ -100,7 +102,7 @@ describe('setupJava', () => {
|
|||
|
||||
mockJavaBase = new LocalDistribution(inputs, jdkFile);
|
||||
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
|
||||
expect(spyTcFind).toHaveBeenCalled();
|
||||
expect(spyGetToolcachePath).toHaveBeenCalled();
|
||||
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...`
|
||||
|
@ -117,7 +119,7 @@ describe('setupJava', () => {
|
|||
|
||||
mockJavaBase = new LocalDistribution(inputs, jdkFile);
|
||||
await expect(mockJavaBase.setupJava()).resolves.toEqual(expected);
|
||||
expect(spyTcFind).toHaveBeenCalled();
|
||||
expect(spyGetToolcachePath).toHaveBeenCalled();
|
||||
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...`
|
||||
|
|
|
@ -96,7 +96,10 @@ describe('findPackageForDownload', () => {
|
|||
['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', '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,
|
||||
|
@ -111,7 +114,7 @@ describe('findPackageForDownload', () => {
|
|||
it('select correct bundle if there are multiple items with the same jdk version but different zulu versions', async () => {
|
||||
const distribution = new ZuluDistribution({ version: '', arch: 'x86', packageType: 'jdk' });
|
||||
distribution['getAvailableVersions'] = async () => manifestData;
|
||||
const result = await distribution['findPackageForDownload'](new semver.Range('11.0.5'));
|
||||
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'
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue