2022-09-27 20:47:12 +08:00
|
|
|
import * as io from '@actions/io';
|
2022-09-29 23:45:25 +08:00
|
|
|
import * as core from '@actions/core';
|
2022-09-27 20:47:12 +08:00
|
|
|
import fs from 'fs';
|
|
|
|
import os from 'os';
|
|
|
|
import path from 'path';
|
2020-09-16 00:36:09 +08:00
|
|
|
|
|
|
|
import * as setup from '../src/setup-dotnet';
|
2022-09-27 20:47:12 +08:00
|
|
|
import {IS_WINDOWS} from '../src/utils';
|
|
|
|
import {IS_LINUX} from '../src/utils';
|
|
|
|
|
|
|
|
let toolDir: string;
|
2020-09-16 00:36:09 +08:00
|
|
|
|
2022-09-27 20:47:12 +08:00
|
|
|
if (IS_WINDOWS) {
|
|
|
|
toolDir = path.join(process.env['PROGRAMFILES'] + '', 'dotnet');
|
|
|
|
} else if (IS_LINUX) {
|
|
|
|
toolDir = '/usr/share/dotnet';
|
|
|
|
} else {
|
|
|
|
toolDir = path.join(process.env['HOME'] + '', '.dotnet');
|
|
|
|
}
|
|
|
|
|
|
|
|
const tempDir = path.join(__dirname, 'runner', 'temp2');
|
2020-09-16 00:36:09 +08:00
|
|
|
|
2021-08-20 21:47:49 +08:00
|
|
|
describe('setup-dotnet tests', () => {
|
2022-09-29 23:45:25 +08:00
|
|
|
let getInputSpy = jest.spyOn(core, 'getInput');
|
|
|
|
let getMultilineInputSpy = jest.spyOn(core, 'getMultilineInput');
|
|
|
|
let setOutputSpy = jest.spyOn(core, 'setOutput');
|
|
|
|
|
|
|
|
let inputs = {} as any;
|
|
|
|
|
2020-09-16 00:36:09 +08:00
|
|
|
beforeAll(async () => {
|
|
|
|
process.env.RUNNER_TOOL_CACHE = toolDir;
|
|
|
|
process.env.DOTNET_INSTALL_DIR = toolDir;
|
|
|
|
process.env.RUNNER_TEMP = tempDir;
|
2022-09-27 20:47:12 +08:00
|
|
|
try {
|
|
|
|
await io.rmRF(`${toolDir}/*`);
|
|
|
|
await io.rmRF(`${tempDir}/*`);
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err.message);
|
|
|
|
console.log('Failed to remove test directories');
|
|
|
|
}
|
|
|
|
}, 30000);
|
2020-09-16 00:36:09 +08:00
|
|
|
|
2021-08-20 21:54:24 +08:00
|
|
|
afterEach(async () => {
|
2020-09-16 00:36:09 +08:00
|
|
|
try {
|
|
|
|
await io.rmRF(path.join(process.cwd(), 'global.json'));
|
2022-09-27 20:47:12 +08:00
|
|
|
await io.rmRF(`${toolDir}/*`);
|
|
|
|
await io.rmRF(`${tempDir}/*`);
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err.message);
|
2020-09-16 00:36:09 +08:00
|
|
|
console.log('Failed to remove test directories');
|
|
|
|
}
|
|
|
|
}, 30000);
|
|
|
|
|
2020-09-24 23:26:00 +08:00
|
|
|
it('Acquires version of dotnet from global.json if no matching version is installed', async () => {
|
2020-09-16 00:36:09 +08:00
|
|
|
const globalJsonPath = path.join(process.cwd(), 'global.json');
|
|
|
|
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "3.1.201"${os.EOL}}${os.EOL}}`;
|
|
|
|
if (!fs.existsSync(globalJsonPath)) {
|
|
|
|
fs.writeFileSync(globalJsonPath, jsonContents);
|
|
|
|
}
|
|
|
|
await setup.run();
|
|
|
|
|
|
|
|
expect(fs.existsSync(path.join(toolDir, 'sdk', '3.1.201'))).toBe(true);
|
|
|
|
if (IS_WINDOWS) {
|
|
|
|
expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true);
|
|
|
|
} else {
|
|
|
|
expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
|
|
|
|
}
|
2020-09-24 23:26:00 +08:00
|
|
|
}, 400000);
|
2022-09-29 23:45:25 +08:00
|
|
|
|
|
|
|
it("Sets output with the latest installed by action version if global.json file isn't specified", async () => {
|
|
|
|
inputs['dotnet-version'] = ['3.1.201', '6.0.401'];
|
|
|
|
|
|
|
|
getMultilineInputSpy.mockImplementation(input => inputs[input]);
|
|
|
|
|
|
|
|
await setup.run();
|
|
|
|
|
|
|
|
expect(setOutputSpy).toBeCalledWith('dotnet-version', '6.0.401');
|
|
|
|
}, 400000);
|
|
|
|
|
|
|
|
it("Sets output with the version specified in global.json, if it's present", async () => {
|
|
|
|
const globalJsonPath = path.join(process.cwd(), 'global.json');
|
|
|
|
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "3.0.103"${os.EOL}}${os.EOL}}`;
|
|
|
|
if (!fs.existsSync(globalJsonPath)) {
|
|
|
|
fs.writeFileSync(globalJsonPath, jsonContents);
|
|
|
|
}
|
|
|
|
|
|
|
|
inputs['dotnet-version'] = ['3.1.201', '6.0.401'];
|
|
|
|
inputs['global-json-file'] = './global.json';
|
|
|
|
|
|
|
|
getMultilineInputSpy.mockImplementation(input => inputs[input]);
|
|
|
|
|
|
|
|
getInputSpy.mockImplementation(input => inputs[input]);
|
|
|
|
|
|
|
|
await setup.run();
|
|
|
|
|
|
|
|
expect(setOutputSpy).toBeCalledWith('dotnet-version', '3.0.103');
|
|
|
|
}, 400000);
|
2020-09-16 00:36:09 +08:00
|
|
|
});
|