Amend unit tests

This commit is contained in:
panticmilos 2022-07-18 12:31:20 +02:00
parent 2dd90ca26f
commit e6b5cf91d5

View file

@ -2,6 +2,7 @@ import * as core from '@actions/core';
import * as cache from '@actions/cache'; import * as cache from '@actions/cache';
import * as exec from '@actions/exec'; import * as exec from '@actions/exec';
import {getCacheDistributor} from '../src/cache-distributions/cache-factory'; import {getCacheDistributor} from '../src/cache-distributions/cache-factory';
import * as utils from './../src/utils';
describe('restore-cache', () => { describe('restore-cache', () => {
const pipFileLockHash = const pipFileLockHash =
@ -27,6 +28,7 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
let debugSpy: jest.SpyInstance; let debugSpy: jest.SpyInstance;
let saveSatetSpy: jest.SpyInstance; let saveSatetSpy: jest.SpyInstance;
let getStateSpy: jest.SpyInstance; let getStateSpy: jest.SpyInstance;
let computeKeysSpy: jest.SpyInstance;
let setOutputSpy: jest.SpyInstance; let setOutputSpy: jest.SpyInstance;
// cache spy // cache spy
@ -74,6 +76,8 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
return primaryKey; return primaryKey;
} }
); );
computeKeysSpy = jest.spyOn(utils, 'getLinuxOSReleaseInfo');
}); });
describe('Validate provided package manager', () => { describe('Validate provided package manager', () => {
@ -109,11 +113,21 @@ virtualenvs.path = "{cache-dir}/virtualenvs" # /Users/patrick/Library/Caches/py
pythonVersion, pythonVersion,
dependencyFile dependencyFile
); );
if (process.env['RUNNER_OS'] === 'linux') {
computeKeysSpy.mockImplementation(() => 'Ubuntu-20.4');
}
await cacheDistributor.restoreCache(); await cacheDistributor.restoreCache();
if (process.env['RUNNER_OS'] === 'linux') {
expect(infoSpy).toHaveBeenCalledWith(
`Cache restored from key: setup-python-${process.env['RUNNER_OS']}-Ubuntu-20.4-python-${pythonVersion}-${packageManager}-${fileHash}`
);
} else {
expect(infoSpy).toHaveBeenCalledWith( expect(infoSpy).toHaveBeenCalledWith(
`Cache restored from key: setup-python-${process.env['RUNNER_OS']}-python-${pythonVersion}-${packageManager}-${fileHash}` `Cache restored from key: setup-python-${process.env['RUNNER_OS']}-python-${pythonVersion}-${packageManager}-${fileHash}`
); );
}
}, },
30000 30000
); );