mirror of
https://github.com/actions/setup-go.git
synced 2025-04-24 01:50:52 +00:00
Add unit test
This commit is contained in:
parent
930ff22596
commit
93ae31f0a4
2 changed files with 38 additions and 2 deletions
|
@ -3,7 +3,7 @@ import * as io from '@actions/io';
|
|||
import * as tc from '@actions/tool-cache';
|
||||
import fs from 'fs';
|
||||
import cp from 'child_process';
|
||||
import osm from 'os';
|
||||
import osm, {type} from 'os';
|
||||
import path from 'path';
|
||||
import * as main from '../src/main';
|
||||
import * as im from '../src/installer';
|
||||
|
@ -11,6 +11,7 @@ import * as im from '../src/installer';
|
|||
import goJsonData from './data/golang-dl.json';
|
||||
import matchers from '../matchers.json';
|
||||
import goTestManifest from './data/versions-manifest.json';
|
||||
import {addExecutablesToCache, IGoVersionInfo} from '../src/installer';
|
||||
const matcherPattern = matchers.problemMatcher[0].pattern[0];
|
||||
const matcherRegExp = new RegExp(matcherPattern.regexp);
|
||||
const win32Join = path.win32.join;
|
||||
|
@ -957,4 +958,39 @@ use .
|
|||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('Windows performance workaround', () => {
|
||||
it('addExecutablesToCache should depends on env[RUNNER_TOOL_CACHE]', async () => {
|
||||
const statSpy = jest.spyOn(fs, 'statSync');
|
||||
// @ts-ignore
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -164,7 +164,7 @@ async function resolveVersionFromManifest(
|
|||
}
|
||||
}
|
||||
|
||||
async function addExecutablesToCache(
|
||||
export async function addExecutablesToCache(
|
||||
extPath: string,
|
||||
info: IGoVersionInfo,
|
||||
arch: string
|
||||
|
|
Loading…
Add table
Reference in a new issue