diff --git a/__tests__/distributors/base-installer.test.ts b/__tests__/distributors/base-installer.test.ts index 177c7ace..17446074 100644 --- a/__tests__/distributors/base-installer.test.ts +++ b/__tests__/distributors/base-installer.test.ts @@ -12,6 +12,8 @@ import { JavaInstallerResults } from '../../src/distributions/base-models'; +import os from 'os'; + class EmptyJavaBase extends JavaBase { constructor(installerOptions: JavaInstallerOptions) { super('Empty', installerOptions); @@ -192,6 +194,8 @@ describe('setupJava', () => { spyCoreSetOutput = jest.spyOn(core, 'setOutput'); spyCoreSetOutput.mockImplementation(() => undefined); + + jest.spyOn(os, 'arch').mockReturnValue('x86'); }); afterEach(() => { @@ -212,6 +216,10 @@ describe('setupJava', () => { [ { 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 } ] ])('should find java locally for %s', (input, expected) => { mockJavaBase = new EmptyJavaBase(input); @@ -237,6 +245,10 @@ describe('setupJava', () => { [ { 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' } ] ])('download java with configuration %s', async (input, expected) => { mockJavaBase = new EmptyJavaBase(input); @@ -256,6 +268,10 @@ describe('setupJava', () => { [ { 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 } ] ])('should check the latest java version for %s and resolve locally', async (input, expected) => { mockJavaBase = new EmptyJavaBase(input); @@ -279,6 +295,10 @@ describe('setupJava', () => { [ { 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 } ] ])('should check the latest java version for %s and download', async (input, expected) => { mockJavaBase = new EmptyJavaBase(input); diff --git a/__tests__/distributors/temurin-installer.test.ts b/__tests__/distributors/temurin-installer.test.ts index c8904f8f..58169650 100644 --- a/__tests__/distributors/temurin-installer.test.ts +++ b/__tests__/distributors/temurin-installer.test.ts @@ -1,5 +1,5 @@ import { HttpClient } from '@actions/http-client'; - +import os from 'os'; import { TemurinDistribution, TemurinImplementation @@ -109,6 +109,30 @@ describe('getAvailableVersions', () => { 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', () => {