fix tests

This commit is contained in:
Salman Muin Kayser Chishti 2025-07-31 20:32:42 +01:00
commit bb39e340a4
14 changed files with 72 additions and 18 deletions

View file

@ -8,6 +8,10 @@ import {JavaInstallerOptions} from '../../src/distributions/base-models';
import os from 'os';
function mockArchitecture(arch: string): NodeJS.Architecture {
return arch as NodeJS.Architecture;
}
import manifestData from '../data/adopt.json';
describe('getAvailableVersions', () => {
@ -191,7 +195,7 @@ describe('getAvailableVersions', () => {
])(
'defaults to os.arch(): %s mapped to distro arch: %s',
async (osArch: string, distroArch: string) => {
jest.spyOn(os, 'arch').mockReturnValue(osArch);
jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch));
const installerOptions: JavaInstallerOptions = {
version: '17',

View file

@ -14,6 +14,10 @@ import {
import os from 'os';
function mockArchitecture(arch: string): NodeJS.Architecture {
return arch as NodeJS.Architecture;
}
class EmptyJavaBase extends JavaBase {
constructor(installerOptions: JavaInstallerOptions) {
super('Empty', installerOptions);
@ -287,7 +291,7 @@ describe('setupJava', () => {
spyCoreSetOutput = jest.spyOn(core, 'setOutput');
spyCoreSetOutput.mockImplementation(() => undefined);
jest.spyOn(os, 'arch').mockReturnValue('x86');
jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture('x86'));
});
afterEach(() => {

View file

@ -6,6 +6,10 @@ import * as util from '../../src/util';
import os from 'os';
import {isGeneratorFunction} from 'util/types';
function mockArchitecture(arch: string): NodeJS.Architecture {
return arch as NodeJS.Architecture;
}
import manifestData from '../data/corretto.json';
describe('getAvailableVersions', () => {
@ -208,7 +212,7 @@ describe('getAvailableVersions', () => {
])(
'defaults to os.arch(): %s mapped to distro arch: %s',
async (osArch: string, distroArch: string) => {
jest.spyOn(os, 'arch').mockReturnValue(osArch);
jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch));
const version = '17';
const installerOptions: JavaInstallerOptions = {

View file

@ -1,5 +1,9 @@
import {GraalVMDistribution} from '../../src/distributions/graalvm/installer';
import os from 'os';
function mockArchitecture(arch: string): NodeJS.Architecture {
return arch as NodeJS.Architecture;
}
import * as core from '@actions/core';
import {getDownloadArchiveExtension} from '../../src/util';
import {HttpClient} from '@actions/http-client';
@ -103,7 +107,7 @@ describe('findPackageForDownload', () => {
])(
'defaults to os.arch(): %s mapped to distro arch: %s',
async (osArch: string, distroArch: string) => {
jest.spyOn(os, 'arch').mockReturnValue(osArch);
jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch));
jest.spyOn(os, 'platform').mockReturnValue('linux');
const version = '21';

View file

@ -6,6 +6,10 @@ import {
import {HttpClient} from '@actions/http-client';
import os from 'os';
function mockArchitecture(arch: string): NodeJS.Architecture {
return arch as NodeJS.Architecture;
}
import manifestData from '../data/liberica.json';
describe('getAvailableVersions', () => {
@ -105,7 +109,7 @@ describe('getAvailableVersions', () => {
])(
'defaults to os.arch(): %s mapped to distro arch: %s',
async (osArch: string, distroArch: DistroArch) => {
jest.spyOn(os, 'arch').mockReturnValue(osArch);
jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch));
const distribution = new LibericaDistributions({
version: '17',

View file

@ -6,6 +6,10 @@ import {
import {HttpClient} from '@actions/http-client';
import os from 'os';
function mockArchitecture(arch: string): NodeJS.Architecture {
return arch as NodeJS.Architecture;
}
import manifestData from '../data/liberica-linux.json';
describe('getAvailableVersions', () => {
@ -105,7 +109,7 @@ describe('getAvailableVersions', () => {
])(
'defaults to os.arch(): %s mapped to distro arch: %s',
async (osArch: string, distroArch: DistroArch) => {
jest.spyOn(os, 'arch').mockReturnValue(osArch);
jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch));
const distribution = new LibericaDistributions({
version: '17',

View file

@ -6,6 +6,10 @@ import {
import {HttpClient} from '@actions/http-client';
import os from 'os';
function mockArchitecture(arch: string): NodeJS.Architecture {
return arch as NodeJS.Architecture;
}
import manifestData from '../data/liberica-windows.json';
describe('getAvailableVersions', () => {
@ -105,7 +109,7 @@ describe('getAvailableVersions', () => {
])(
'defaults to os.arch(): %s mapped to distro arch: %s',
async (osArch: string, distroArch: DistroArch) => {
jest.spyOn(os, 'arch').mockReturnValue(osArch);
jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch));
const distribution = new LibericaDistributions({
version: '17',

View file

@ -1,5 +1,9 @@
import {MicrosoftDistributions} from '../../src/distributions/microsoft/installer';
import os from 'os';
function mockArchitecture(arch: string): NodeJS.Architecture {
return arch as NodeJS.Architecture;
}
import data from '../data/microsoft.json';
import * as httpm from '@actions/http-client';
import * as core from '@actions/core';
@ -95,7 +99,7 @@ describe('findPackageForDownload', () => {
])(
'defaults to os.arch(): %s mapped to distro arch: %s',
async (osArch: string, distroArch: string) => {
jest.spyOn(os, 'arch').mockReturnValue(osArch);
jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch));
jest.spyOn(os, 'platform').mockReturnValue('darwin');
const version = '17';
@ -119,7 +123,7 @@ describe('findPackageForDownload', () => {
])(
'defaults to os.arch(): %s mapped to distro arch: %s',
async (osArch: string, distroArch: string) => {
jest.spyOn(os, 'arch').mockReturnValue(osArch);
jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch));
jest.spyOn(os, 'platform').mockReturnValue('linux');
const version = '17';
@ -143,7 +147,7 @@ describe('findPackageForDownload', () => {
])(
'defaults to os.arch(): %s mapped to distro arch: %s',
async (osArch: string, distroArch: string) => {
jest.spyOn(os, 'arch').mockReturnValue(osArch);
jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch));
jest.spyOn(os, 'platform').mockReturnValue('win32');
const version = '17';

View file

@ -1,5 +1,9 @@
import {OracleDistribution} from '../../src/distributions/oracle/installer';
import os from 'os';
function mockArchitecture(arch: string): NodeJS.Architecture {
return arch as NodeJS.Architecture;
}
import * as core from '@actions/core';
import {getDownloadArchiveExtension} from '../../src/util';
import {HttpClient} from '@actions/http-client';
@ -95,7 +99,7 @@ describe('findPackageForDownload', () => {
])(
'defaults to os.arch(): %s mapped to distro arch: %s',
async (osArch: string, distroArch: string) => {
jest.spyOn(os, 'arch').mockReturnValue(osArch);
jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch));
jest.spyOn(os, 'platform').mockReturnValue('linux');
const version = '18';

View file

@ -1,5 +1,9 @@
import {HttpClient} from '@actions/http-client';
import os from 'os';
function mockArchitecture(arch: string): NodeJS.Architecture {
return arch as NodeJS.Architecture;
}
import {
TemurinDistribution,
TemurinImplementation
@ -147,7 +151,7 @@ describe('getAvailableVersions', () => {
])(
'defaults to os.arch(): %s mapped to distro arch: %s',
async (osArch: string, distroArch: string) => {
jest.spyOn(os, 'arch').mockReturnValue(distroArch);
jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(distroArch));
const installerOptions: JavaInstallerOptions = {
version: '17',

View file

@ -5,6 +5,10 @@ import {IZuluVersions} from '../../src/distributions/zulu/models';
import * as utils from '../../src/util';
import os from 'os';
function mockArchitecture(arch: string): NodeJS.Architecture {
return arch as NodeJS.Architecture;
}
import manifestData from '../data/zulu-releases-default.json';
describe('getAvailableVersions', () => {
@ -126,7 +130,7 @@ describe('getAvailableVersions', () => {
])(
'defaults to os.arch(): %s mapped to distro arch: %s',
async (osArch: string, distroArch: DistroArch) => {
jest.spyOn(os, 'arch').mockReturnValue(osArch);
jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch));
const distribution = new ZuluDistribution({
version: '17',

View file

@ -5,6 +5,10 @@ import {IZuluVersions} from '../../src/distributions/zulu/models';
import * as utils from '../../src/util';
import os from 'os';
function mockArchitecture(arch: string): NodeJS.Architecture {
return arch as NodeJS.Architecture;
}
import manifestData from '../data/zulu-linux.json';
describe('getAvailableVersions', () => {
@ -126,7 +130,7 @@ describe('getAvailableVersions', () => {
])(
'defaults to os.arch(): %s mapped to distro arch: %s',
async (osArch: string, distroArch: DistroArch) => {
jest.spyOn(os, 'arch').mockReturnValue(osArch);
jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch));
const distribution = new ZuluDistribution({
version: '17',

View file

@ -5,6 +5,10 @@ import {IZuluVersions} from '../../src/distributions/zulu/models';
import * as utils from '../../src/util';
import os from 'os';
function mockArchitecture(arch: string): NodeJS.Architecture {
return arch as NodeJS.Architecture;
}
import manifestData from '../data/zulu-windows.json';
describe('getAvailableVersions', () => {
@ -126,7 +130,7 @@ describe('getAvailableVersions', () => {
])(
'defaults to os.arch(): %s mapped to distro arch: %s',
async (osArch: string, distroArch: DistroArch) => {
jest.spyOn(os, 'arch').mockReturnValue(osArch);
jest.spyOn(os, 'arch').mockReturnValue(mockArchitecture(osArch));
const distribution = new ZuluDistribution({
version: '17',

View file

@ -6,7 +6,8 @@ import * as io from '@actions/io';
import * as toolchains from '../src/toolchains';
import {M2_DIR, MVN_TOOLCHAINS_FILE} from '../src/constants';
const m2Dir = path.join(__dirname, M2_DIR);
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'setup-java-test-'));
const m2Dir = path.join(tempDir, M2_DIR);
const toolchainsFile = path.join(m2Dir, MVN_TOOLCHAINS_FILE);
describe('toolchains tests', () => {
@ -16,7 +17,7 @@ describe('toolchains tests', () => {
beforeEach(async () => {
await io.rmRF(m2Dir);
spyOSHomedir = jest.spyOn(os, 'homedir');
spyOSHomedir.mockReturnValue(__dirname);
spyOSHomedir.mockReturnValue(tempDir);
spyInfo = jest.spyOn(core, 'info');
spyInfo.mockImplementation(() => null);
}, 300000);
@ -24,6 +25,7 @@ describe('toolchains tests', () => {
afterAll(async () => {
try {
await io.rmRF(m2Dir);
await io.rmRF(tempDir);
} catch {
console.log('Failed to remove test directories');
}
@ -40,7 +42,7 @@ describe('toolchains tests', () => {
jdkHome: '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64'
};
const altHome = path.join(__dirname, 'runner', 'toolchains');
const altHome = path.join(tempDir, 'runner', 'toolchains');
const altToolchainsFile = path.join(altHome, MVN_TOOLCHAINS_FILE);
await io.rmRF(altHome); // ensure it doesn't already exist