Add tests for os.arch() default behavior
This commit is contained in:
parent
e169777d50
commit
c22bb804ce
@ -12,6 +12,8 @@ import {
|
|||||||
JavaInstallerResults
|
JavaInstallerResults
|
||||||
} from '../../src/distributions/base-models';
|
} from '../../src/distributions/base-models';
|
||||||
|
|
||||||
|
import os from 'os';
|
||||||
|
|
||||||
class EmptyJavaBase extends JavaBase {
|
class EmptyJavaBase extends JavaBase {
|
||||||
constructor(installerOptions: JavaInstallerOptions) {
|
constructor(installerOptions: JavaInstallerOptions) {
|
||||||
super('Empty', installerOptions);
|
super('Empty', installerOptions);
|
||||||
@ -192,6 +194,8 @@ describe('setupJava', () => {
|
|||||||
|
|
||||||
spyCoreSetOutput = jest.spyOn(core, 'setOutput');
|
spyCoreSetOutput = jest.spyOn(core, 'setOutput');
|
||||||
spyCoreSetOutput.mockImplementation(() => undefined);
|
spyCoreSetOutput.mockImplementation(() => undefined);
|
||||||
|
|
||||||
|
jest.spyOn(os, 'arch').mockReturnValue('x86');
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@ -212,6 +216,10 @@ describe('setupJava', () => {
|
|||||||
[
|
[
|
||||||
{ version: '11.0.8', architecture: 'x86', packageType: 'jdk', checkLatest: false },
|
{ version: '11.0.8', architecture: 'x86', packageType: 'jdk', checkLatest: false },
|
||||||
{ version: installedJavaVersion, path: javaPath }
|
{ 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', (input, expected) => {
|
||||||
mockJavaBase = new EmptyJavaBase(input);
|
mockJavaBase = new EmptyJavaBase(input);
|
||||||
@ -237,6 +245,10 @@ describe('setupJava', () => {
|
|||||||
[
|
[
|
||||||
{ version: '11', architecture: 'x64', packageType: 'jre', checkLatest: false },
|
{ version: '11', architecture: 'x64', packageType: 'jre', checkLatest: false },
|
||||||
{ path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x64'), version: '11.0.9' }
|
{ 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' }
|
||||||
]
|
]
|
||||||
])('download java with configuration %s', async (input, expected) => {
|
])('download java with configuration %s', async (input, expected) => {
|
||||||
mockJavaBase = new EmptyJavaBase(input);
|
mockJavaBase = new EmptyJavaBase(input);
|
||||||
@ -256,6 +268,10 @@ describe('setupJava', () => {
|
|||||||
[
|
[
|
||||||
{ version: '11.0.9', architecture: 'x86', packageType: 'jdk', checkLatest: true },
|
{ version: '11.0.9', architecture: 'x86', packageType: 'jdk', checkLatest: true },
|
||||||
{ version: '11.0.9', path: javaPathInstalled }
|
{ 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) => {
|
])('should check the latest java version for %s and resolve locally', async (input, expected) => {
|
||||||
mockJavaBase = new EmptyJavaBase(input);
|
mockJavaBase = new EmptyJavaBase(input);
|
||||||
@ -279,6 +295,10 @@ describe('setupJava', () => {
|
|||||||
[
|
[
|
||||||
{ version: '11.0.x', architecture: 'x86', packageType: 'jdk', checkLatest: true },
|
{ version: '11.0.x', architecture: 'x86', packageType: 'jdk', checkLatest: true },
|
||||||
{ version: actualJavaVersion, path: javaPathInstalled }
|
{ 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) => {
|
])('should check the latest java version for %s and download', async (input, expected) => {
|
||||||
mockJavaBase = new EmptyJavaBase(input);
|
mockJavaBase = new EmptyJavaBase(input);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { HttpClient } from '@actions/http-client';
|
import { HttpClient } from '@actions/http-client';
|
||||||
|
import os from 'os';
|
||||||
import {
|
import {
|
||||||
TemurinDistribution,
|
TemurinDistribution,
|
||||||
TemurinImplementation
|
TemurinImplementation
|
||||||
@ -109,6 +109,30 @@ describe('getAvailableVersions', () => {
|
|||||||
expect(distribution.toolcacheFolderName).toBe(expected);
|
expect(distribution.toolcacheFolderName).toBe(expected);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
it('defaults to os.arch() mapped to temurin arch', async () => {
|
||||||
|
jest.spyOn(os, 'arch').mockReturnValue('amd64');
|
||||||
|
|
||||||
|
const installerOptions: JavaInstallerOptions = {
|
||||||
|
version: '17',
|
||||||
|
architecture: '',
|
||||||
|
packageType: 'jdk',
|
||||||
|
checkLatest: false
|
||||||
|
};
|
||||||
|
|
||||||
|
const expectedParameters =
|
||||||
|
'os=mac&architecture=x64&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 expectedUrl = `${baseUrl}?project=jdk&vendor=adoptium&heap_size=normal&sort_method=DEFAULT&sort_order=DESC&${expectedParameters}`;
|
||||||
|
distribution['getPlatformOption'] = () => 'mac';
|
||||||
|
|
||||||
|
await distribution['getAvailableVersions']();
|
||||||
|
|
||||||
|
expect(spyHttpClient.mock.calls).toHaveLength(1);
|
||||||
|
expect(spyHttpClient.mock.calls[0][0]).toBe(expectedUrl);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('findPackageForDownload', () => {
|
describe('findPackageForDownload', () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user