mirror of
https://github.com/actions/setup-java.git
synced 2026-03-25 05:10:36 +00:00
Mock core.error in tests to suppress error logs
This commit is contained in:
parent
d78498f580
commit
97169f0244
@ -17,6 +17,7 @@ describe('dependency cache', () => {
|
||||
let spyWarning: jest.SpyInstance<void, Parameters<typeof core.warning>>;
|
||||
let spyDebug: jest.SpyInstance<void, Parameters<typeof core.debug>>;
|
||||
let spySaveState: jest.SpyInstance<void, Parameters<typeof core.saveState>>;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
workspace = mkdtempSync(join(tmpdir(), 'setup-java-cache-'));
|
||||
@ -51,6 +52,10 @@ describe('dependency cache', () => {
|
||||
|
||||
spySaveState = jest.spyOn(core, 'saveState');
|
||||
spySaveState.mockImplementation(() => null);
|
||||
|
||||
// Mock core.error to suppress error logs
|
||||
spyCoreError = jest.spyOn(core, 'error');
|
||||
spyCoreError.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@ -58,6 +63,10 @@ describe('dependency cache', () => {
|
||||
process.env['GITHUB_WORKSPACE'] = ORIGINAL_GITHUB_WORKSPACE;
|
||||
process.env['RUNNER_OS'] = ORIGINAL_RUNNER_OS;
|
||||
resetState();
|
||||
|
||||
jest.resetAllMocks();
|
||||
jest.clearAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe('restore', () => {
|
||||
|
||||
@ -11,19 +11,32 @@ describe('cleanup', () => {
|
||||
Parameters<typeof cache.saveCache>
|
||||
>;
|
||||
let spyJobStatusSuccess: jest.SpyInstance;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyWarning = jest.spyOn(core, 'warning');
|
||||
spyWarning.mockImplementation(() => null);
|
||||
|
||||
spyInfo = jest.spyOn(core, 'info');
|
||||
spyInfo.mockImplementation(() => null);
|
||||
|
||||
spyCacheSave = jest.spyOn(cache, 'saveCache');
|
||||
|
||||
spyJobStatusSuccess = jest.spyOn(util, 'isJobStatusSuccess');
|
||||
spyJobStatusSuccess.mockReturnValue(true);
|
||||
|
||||
// Mock core.error to suppress error logs
|
||||
spyCoreError = jest.spyOn(core, 'error');
|
||||
spyCoreError.mockImplementation(() => {});
|
||||
|
||||
createStateForSuccessfulRestore();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
resetState();
|
||||
jest.resetAllMocks();
|
||||
jest.clearAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('does not fail nor warn even when the save process throws a ReserveCacheError', async () => {
|
||||
|
||||
@ -9,9 +9,11 @@ import {JavaInstallerOptions} from '../../src/distributions/base-models';
|
||||
import os from 'os';
|
||||
|
||||
import manifestData from '../data/adopt.json';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
describe('getAvailableVersions', () => {
|
||||
let spyHttpClient: jest.SpyInstance;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||
@ -20,6 +22,10 @@ describe('getAvailableVersions', () => {
|
||||
headers: {},
|
||||
result: []
|
||||
});
|
||||
|
||||
// Mock core.error to suppress error logs
|
||||
spyCoreError = jest.spyOn(core, 'error');
|
||||
spyCoreError.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@ -248,6 +248,7 @@ describe('setupJava', () => {
|
||||
let spyCoreExportVariable: jest.SpyInstance;
|
||||
let spyCoreAddPath: jest.SpyInstance;
|
||||
let spyCoreSetOutput: jest.SpyInstance;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyGetToolcachePath = jest.spyOn(util, 'getToolcachePath');
|
||||
@ -287,6 +288,10 @@ describe('setupJava', () => {
|
||||
spyCoreSetOutput = jest.spyOn(core, 'setOutput');
|
||||
spyCoreSetOutput.mockImplementation(() => undefined);
|
||||
|
||||
// Mock core.error to suppress error logs
|
||||
spyCoreError = jest.spyOn(core, 'error');
|
||||
spyCoreError.mockImplementation(() => undefined);
|
||||
|
||||
jest.spyOn(os, 'arch').mockReturnValue('x86' as ReturnType<typeof os.arch>);
|
||||
});
|
||||
|
||||
|
||||
@ -4,13 +4,14 @@ import {JavaInstallerOptions} from '../../src/distributions/base-models';
|
||||
import {CorrettoDistribution} from '../../src/distributions/corretto/installer';
|
||||
import * as util from '../../src/util';
|
||||
import os from 'os';
|
||||
import {isGeneratorFunction} from 'util/types';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
import manifestData from '../data/corretto.json';
|
||||
|
||||
describe('getAvailableVersions', () => {
|
||||
let spyHttpClient: jest.SpyInstance;
|
||||
let spyGetDownloadArchiveExtension: jest.SpyInstance;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||
@ -23,6 +24,10 @@ describe('getAvailableVersions', () => {
|
||||
util,
|
||||
'getDownloadArchiveExtension'
|
||||
);
|
||||
|
||||
// Mock core.error to suppress error logs
|
||||
spyCoreError = jest.spyOn(core, 'error');
|
||||
spyCoreError.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
import {HttpClient} from '@actions/http-client';
|
||||
import {DragonwellDistribution} from '../../src/distributions/dragonwell/installer';
|
||||
import * as utils from '../../src/util';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
import manifestData from '../data/dragonwell.json';
|
||||
|
||||
describe('getAvailableVersions', () => {
|
||||
let spyHttpClient: jest.SpyInstance;
|
||||
let spyUtilGetDownloadArchiveExtension: jest.SpyInstance;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||
@ -21,6 +23,10 @@ describe('getAvailableVersions', () => {
|
||||
'getDownloadArchiveExtension'
|
||||
);
|
||||
spyUtilGetDownloadArchiveExtension.mockReturnValue('tar.gz');
|
||||
|
||||
// Mock core.error to suppress error logs
|
||||
spyCoreError = jest.spyOn(core, 'error');
|
||||
spyCoreError.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@ -42,6 +42,7 @@ beforeAll(() => {
|
||||
describe('GraalVMDistribution', () => {
|
||||
let distribution: GraalVMDistribution;
|
||||
let mockHttpClient: jest.Mocked<http.HttpClient>;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
|
||||
const defaultOptions: JavaInstallerOptions = {
|
||||
version: '17',
|
||||
@ -59,6 +60,10 @@ describe('GraalVMDistribution', () => {
|
||||
(distribution as any).http = mockHttpClient;
|
||||
|
||||
(util.getDownloadArchiveExtension as jest.Mock).mockReturnValue('tar.gz');
|
||||
|
||||
// Mock core.error to suppress error logs
|
||||
spyCoreError = jest.spyOn(core, 'error');
|
||||
spyCoreError.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
|
||||
@ -4,9 +4,11 @@ import {JetBrainsDistribution} from '../../src/distributions/jetbrains/installer
|
||||
|
||||
import manifestData from '../data/jetbrains.json';
|
||||
import os from 'os';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
describe('getAvailableVersions', () => {
|
||||
let spyHttpClient: jest.SpyInstance;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||
@ -15,6 +17,10 @@ describe('getAvailableVersions', () => {
|
||||
headers: {},
|
||||
result: []
|
||||
});
|
||||
|
||||
// Mock core.error to suppress error logs
|
||||
spyCoreError = jest.spyOn(core, 'error');
|
||||
spyCoreError.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@ -5,11 +5,13 @@ import {
|
||||
} from '../../src/distributions/liberica/models';
|
||||
import {HttpClient} from '@actions/http-client';
|
||||
import os from 'os';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
import manifestData from '../data/liberica.json';
|
||||
|
||||
describe('getAvailableVersions', () => {
|
||||
let spyHttpClient: jest.SpyInstance;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||
@ -18,6 +20,10 @@ describe('getAvailableVersions', () => {
|
||||
headers: {},
|
||||
result: manifestData as LibericaVersion[]
|
||||
});
|
||||
|
||||
// Mock core.error to suppress error logs
|
||||
spyCoreError = jest.spyOn(core, 'error');
|
||||
spyCoreError.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@ -5,11 +5,13 @@ import {
|
||||
} from '../../src/distributions/liberica/models';
|
||||
import {HttpClient} from '@actions/http-client';
|
||||
import os from 'os';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
import manifestData from '../data/liberica-linux.json';
|
||||
|
||||
describe('getAvailableVersions', () => {
|
||||
let spyHttpClient: jest.SpyInstance;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||
@ -18,6 +20,10 @@ describe('getAvailableVersions', () => {
|
||||
headers: {},
|
||||
result: manifestData as LibericaVersion[]
|
||||
});
|
||||
|
||||
// Mock core.error to suppress error logs
|
||||
spyCoreError = jest.spyOn(core, 'error');
|
||||
spyCoreError.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@ -5,11 +5,13 @@ import {
|
||||
} from '../../src/distributions/liberica/models';
|
||||
import {HttpClient} from '@actions/http-client';
|
||||
import os from 'os';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
import manifestData from '../data/liberica-windows.json';
|
||||
|
||||
describe('getAvailableVersions', () => {
|
||||
let spyHttpClient: jest.SpyInstance;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||
@ -18,6 +20,9 @@ describe('getAvailableVersions', () => {
|
||||
headers: {},
|
||||
result: manifestData as LibericaVersion[]
|
||||
});
|
||||
// Mock core.error to suppress error logs
|
||||
spyCoreError = jest.spyOn(core, 'error');
|
||||
spyCoreError.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@ -27,6 +27,7 @@ describe('setupJava', () => {
|
||||
let spyFsReadDir: jest.SpyInstance;
|
||||
let spyUtilsExtractJdkFile: jest.SpyInstance;
|
||||
let spyPathResolve: jest.SpyInstance;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
const expectedJdkFile = 'JavaLocalJdkFile';
|
||||
|
||||
beforeEach(() => {
|
||||
@ -93,6 +94,10 @@ describe('setupJava', () => {
|
||||
// Spy on path methods
|
||||
spyPathResolve = jest.spyOn(path, 'resolve');
|
||||
spyPathResolve.mockImplementation((path: string) => path);
|
||||
|
||||
// Mock core.error to suppress error logs
|
||||
spyCoreError = jest.spyOn(core, 'error');
|
||||
spyCoreError.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@ -8,6 +8,7 @@ describe('findPackageForDownload', () => {
|
||||
let distribution: MicrosoftDistributions;
|
||||
let spyGetManifestFromRepo: jest.SpyInstance;
|
||||
let spyDebug: jest.SpyInstance;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
distribution = new MicrosoftDistributions({
|
||||
@ -26,6 +27,10 @@ describe('findPackageForDownload', () => {
|
||||
|
||||
spyDebug = jest.spyOn(core, 'debug');
|
||||
spyDebug.mockImplementation(() => {});
|
||||
|
||||
// Mock core.error to suppress error logs
|
||||
spyCoreError = jest.spyOn(core, 'error');
|
||||
spyCoreError.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
it.each([
|
||||
|
||||
@ -8,6 +8,7 @@ describe('findPackageForDownload', () => {
|
||||
let distribution: OracleDistribution;
|
||||
let spyDebug: jest.SpyInstance;
|
||||
let spyHttpClient: jest.SpyInstance;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
distribution = new OracleDistribution({
|
||||
@ -19,6 +20,10 @@ describe('findPackageForDownload', () => {
|
||||
|
||||
spyDebug = jest.spyOn(core, 'debug');
|
||||
spyDebug.mockImplementation(() => {});
|
||||
|
||||
// Mock core.error to suppress error logs
|
||||
spyCoreError = jest.spyOn(core, 'error');
|
||||
spyCoreError.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
it.each([
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
import {HttpClient} from '@actions/http-client';
|
||||
import {SapMachineDistribution} from '../../src/distributions/sapmachine/installer';
|
||||
import * as utils from '../../src/util';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
import manifestData from '../data/sapmachine.json';
|
||||
|
||||
describe('getAvailableVersions', () => {
|
||||
let spyHttpClient: jest.SpyInstance;
|
||||
let spyUtilGetDownloadArchiveExtension: jest.SpyInstance;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||
@ -21,6 +23,10 @@ describe('getAvailableVersions', () => {
|
||||
'getDownloadArchiveExtension'
|
||||
);
|
||||
spyUtilGetDownloadArchiveExtension.mockReturnValue('tar.gz');
|
||||
|
||||
// Mock core.error to suppress error logs
|
||||
spyCoreError = jest.spyOn(core, 'error');
|
||||
spyCoreError.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@ -4,9 +4,11 @@ import {JavaInstallerOptions} from '../../src/distributions/base-models';
|
||||
import {SemeruDistribution} from '../../src/distributions/semeru/installer';
|
||||
|
||||
import manifestData from '../data/semeru.json';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
describe('getAvailableVersions', () => {
|
||||
let spyHttpClient: jest.SpyInstance;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||
@ -15,6 +17,9 @@ describe('getAvailableVersions', () => {
|
||||
headers: {},
|
||||
result: []
|
||||
});
|
||||
// Mock core.error to suppress error logs
|
||||
spyCoreError = jest.spyOn(core, 'error');
|
||||
spyCoreError.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@ -7,9 +7,11 @@ import {
|
||||
import {JavaInstallerOptions} from '../../src/distributions/base-models';
|
||||
|
||||
import manifestData from '../data/temurin.json';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
describe('getAvailableVersions', () => {
|
||||
let spyHttpClient: jest.SpyInstance;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||
@ -18,6 +20,9 @@ describe('getAvailableVersions', () => {
|
||||
headers: {},
|
||||
result: []
|
||||
});
|
||||
// Mock core.error to suppress error logs
|
||||
spyCoreError = jest.spyOn(core, 'error');
|
||||
spyCoreError.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@ -3,12 +3,14 @@ import {ZuluDistribution} from '../../src/distributions/zulu/installer';
|
||||
import {IZuluVersions} from '../../src/distributions/zulu/models';
|
||||
import * as utils from '../../src/util';
|
||||
import os from 'os';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
import manifestData from '../data/zulu-releases-default.json';
|
||||
|
||||
describe('getAvailableVersions', () => {
|
||||
let spyHttpClient: jest.SpyInstance;
|
||||
let spyUtilGetDownloadArchiveExtension: jest.SpyInstance;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||
@ -23,6 +25,10 @@ describe('getAvailableVersions', () => {
|
||||
'getDownloadArchiveExtension'
|
||||
);
|
||||
spyUtilGetDownloadArchiveExtension.mockReturnValue('tar.gz');
|
||||
|
||||
// Mock core.error to suppress error logs
|
||||
spyCoreError = jest.spyOn(core, 'error');
|
||||
spyCoreError.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@ -4,12 +4,14 @@ import {ZuluDistribution} from '../../src/distributions/zulu/installer';
|
||||
import {IZuluVersions} from '../../src/distributions/zulu/models';
|
||||
import * as utils from '../../src/util';
|
||||
import os from 'os';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
import manifestData from '../data/zulu-linux.json';
|
||||
|
||||
describe('getAvailableVersions', () => {
|
||||
let spyHttpClient: jest.SpyInstance;
|
||||
let spyUtilGetDownloadArchiveExtension: jest.SpyInstance;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||
@ -24,6 +26,10 @@ describe('getAvailableVersions', () => {
|
||||
'getDownloadArchiveExtension'
|
||||
);
|
||||
spyUtilGetDownloadArchiveExtension.mockReturnValue('zip');
|
||||
|
||||
// Mock core.error to suppress error logs
|
||||
spyCoreError = jest.spyOn(core, 'error');
|
||||
spyCoreError.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@ -4,12 +4,14 @@ import {ZuluDistribution} from '../../src/distributions/zulu/installer';
|
||||
import {IZuluVersions} from '../../src/distributions/zulu/models';
|
||||
import * as utils from '../../src/util';
|
||||
import os from 'os';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
import manifestData from '../data/zulu-windows.json';
|
||||
|
||||
describe('getAvailableVersions', () => {
|
||||
let spyHttpClient: jest.SpyInstance;
|
||||
let spyUtilGetDownloadArchiveExtension: jest.SpyInstance;
|
||||
let spyCoreError: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
|
||||
@ -24,6 +26,10 @@ describe('getAvailableVersions', () => {
|
||||
'getDownloadArchiveExtension'
|
||||
);
|
||||
spyUtilGetDownloadArchiveExtension.mockReturnValue('zip');
|
||||
|
||||
// Mock core.error to suppress error logs
|
||||
spyCoreError = jest.spyOn(core, 'error');
|
||||
spyCoreError.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user