Favor spy with preloaded data over actual download

This commit is contained in:
Manuel 2022-04-03 00:19:21 +02:00
parent cced1ea888
commit a0d1026612
3 changed files with 1208 additions and 5 deletions

View file

@ -1,12 +1,30 @@
import { HttpClient } from '@actions/http-client';
import { CorettoDistribution } from '../../src/distributions/corretto/installer';
import { JavaInstallerOptions } from '../../src/distributions/base-models';
import * as util from '../../src/util';
const manifestData = require('../data/corretto.json') as [];
describe('getAvailableVersions', () => {
beforeEach(() => {});
let spyHttpClient: jest.SpyInstance;
let spyGetDownloadArchiveExtension: jest.SpyInstance;
afterEach(() => {});
beforeEach(() => {
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
spyHttpClient.mockReturnValue({
statusCode: 200,
headers: {},
result: manifestData
});
spyGetDownloadArchiveExtension = jest.spyOn(util, 'getDownloadArchiveExtension');
spyGetDownloadArchiveExtension.mockReturnValue('tar.gz');
});
afterEach(() => {
jest.resetAllMocks();
jest.clearAllMocks();
jest.restoreAllMocks();
});
it('load available versions', async () => {
const distribution = new CorettoDistribution({
@ -15,6 +33,7 @@ describe('getAvailableVersions', () => {
packageType: 'jdk',
checkLatest: false
});
distribution['getPlatformOption'] = () => 'linux';
const availableVersions = await distribution['getAvailableVersions']();
expect(availableVersions).not.toBeNull();
@ -23,11 +42,12 @@ describe('getAvailableVersions', () => {
it('find package for download', async () => {
const distribution = new CorettoDistribution({
version: '11',
version: '15',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
});
distribution['getPlatformOption'] = () => 'linux';
const availableVersion = await distribution['findPackageForDownload']('15');
expect(availableVersion).not.toBeNull();