2022-09-27 19:47:12 +07:00
|
|
|
import * as io from '@actions/io';
|
2022-09-29 22:45:25 +07:00
|
|
|
import * as core from '@actions/core';
|
2022-09-27 19:47:12 +07:00
|
|
|
import fs from 'fs';
|
|
|
|
import os from 'os';
|
|
|
|
import path from 'path';
|
2020-09-15 23:36:09 +07:00
|
|
|
|
|
|
|
import * as setup from '../src/setup-dotnet';
|
2022-09-27 19:47:12 +07:00
|
|
|
import {IS_WINDOWS} from '../src/utils';
|
|
|
|
import {IS_LINUX} from '../src/utils';
|
|
|
|
|
|
|
|
let toolDir: string;
|
2020-09-15 23:36:09 +07:00
|
|
|
|
2022-09-27 19:47:12 +07: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-15 23:36:09 +07:00
|
|
|
|
2021-08-20 20:47:49 +07:00
|
|
|
describe('setup-dotnet tests', () => {
|
2023-03-09 19:43:05 +07:00
|
|
|
const getInputSpy = jest.spyOn(core, 'getInput');
|
|
|
|
const getMultilineInputSpy = jest.spyOn(core, 'getMultilineInput');
|
|
|
|
const setOutputSpy = jest.spyOn(core, 'setOutput');
|
2022-09-29 22:45:25 +07:00
|
|
|
|
2023-03-09 19:43:05 +07:00
|
|
|
const inputs = {} as any;
|
2022-09-29 22:45:25 +07:00
|
|
|
|
2020-09-15 23:36:09 +07:00
|
|
|
beforeAll(async () => {
|
|
|
|
process.env.RUNNER_TOOL_CACHE = toolDir;
|
|
|
|
process.env.DOTNET_INSTALL_DIR = toolDir;
|
|
|
|
process.env.RUNNER_TEMP = tempDir;
|
2022-09-27 19:47:12 +07: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-15 23:36:09 +07:00
|
|
|
|
2021-08-20 20:54:24 +07:00
|
|
|
afterEach(async () => {
|
2020-09-15 23:36:09 +07:00
|
|
|
try {
|
|
|
|
await io.rmRF(path.join(process.cwd(), 'global.json'));
|
2022-09-27 19:47:12 +07:00
|
|
|
await io.rmRF(`${toolDir}/*`);
|
|
|
|
await io.rmRF(`${tempDir}/*`);
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err.message);
|
2020-09-15 23:36:09 +07:00
|
|
|
console.log('Failed to remove test directories');
|
|
|
|
}
|
|
|
|
}, 30000);
|
|
|
|
|
2020-09-24 22:26:00 +07:00
|
|
|
it('Acquires version of dotnet from global.json if no matching version is installed', async () => {
|
2020-09-15 23:36:09 +07: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 22:26:00 +07:00
|
|
|
}, 400000);
|
2022-09-29 22:45:25 +07: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();
|
|
|
|
|
2023-03-09 19:43:05 +07:00
|
|
|
expect(setOutputSpy).toHaveBeenCalledWith('dotnet-version', '6.0.401');
|
2022-09-29 22:45:25 +07:00
|
|
|
}, 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();
|
|
|
|
|
2023-03-09 19:43:05 +07:00
|
|
|
expect(setOutputSpy).toHaveBeenCalledWith('dotnet-version', '3.0.103');
|
2022-09-29 22:45:25 +07:00
|
|
|
}, 400000);
|
2020-09-15 23:36:09 +07:00
|
|
|
});
|