Fix unit tests

This commit is contained in:
Sergey Dolin 2023-07-12 02:08:24 +02:00
parent 99ea9d4780
commit d4fc9881c5
2 changed files with 68 additions and 35 deletions

View file

@ -40,6 +40,8 @@ describe('setup-go', () => {
let existsSpy: jest.SpyInstance;
let readFileSpy: jest.SpyInstance;
let mkdirpSpy: jest.SpyInstance;
let mkdirSpy: jest.SpyInstance;
let symlinkSpy: jest.SpyInstance;
let execSpy: jest.SpyInstance;
let getManifestSpy: jest.SpyInstance;
let getAllVersionsSpy: jest.SpyInstance;
@ -93,6 +95,11 @@ describe('setup-go', () => {
readFileSpy = jest.spyOn(fs, 'readFileSync');
mkdirpSpy = jest.spyOn(io, 'mkdirP');
// fs
mkdirSpy = jest.spyOn(fs, 'mkdir');
symlinkSpy = jest.spyOn(fs, 'symlinkSync');
symlinkSpy.mockImplementation(() => {});
// gets
getManifestSpy.mockImplementation(() => <tc.IToolRelease[]>goTestManifest);
@ -958,39 +965,4 @@ use .
}
);
});
describe('Windows performance workaround', () => {
it('addExecutablesToCache should depends on env[RUNNER_TOOL_CACHE]', async () => {
const statSpy = jest.spyOn(fs, 'statSync');
// @ts-ignore - not implement unused methods
statSpy.mockImplementation(() => ({
isDirectory: () => true
}));
const readdirSpy = jest.spyOn(fs, 'readdirSync');
readdirSpy.mockImplementation(() => []);
const writeFileSpy = jest.spyOn(fs, 'writeFileSync');
writeFileSpy.mockImplementation(() => {});
const rmRFSpy = jest.spyOn(io, 'rmRF');
rmRFSpy.mockImplementation(() => Promise.resolve());
const mkdirPSpy = jest.spyOn(io, 'mkdirP');
mkdirPSpy.mockImplementation(() => Promise.resolve());
const cpSpy = jest.spyOn(io, 'cp');
cpSpy.mockImplementation(() => Promise.resolve());
const info: IGoVersionInfo = {
type: 'dist',
downloadUrl: 'http://nowhere.com',
resolvedVersion: '1.2.3',
fileName: 'ignore'
};
process.env['RUNNER_TOOL_CACHE'] = '/faked-hostedtoolcache1';
const cacheDir1 = await addExecutablesToCache('/qzx', info, 'arch');
expect(cacheDir1).toBe('/faked-hostedtoolcache1/go/1.2.3/arch');
process.env['RUNNER_TOOL_CACHE'] = '/faked-hostedtoolcache2';
const cacheDir2 = await addExecutablesToCache('/qzx', info, 'arch');
expect(cacheDir2).toBe('/faked-hostedtoolcache2/go/1.2.3/arch');
});
});
});