2022-09-27 19:47:12 +07:00
|
|
|
import * as io from '@actions/io';
|
|
|
|
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', () => {
|
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);
|
2020-09-15 23:36:09 +07:00
|
|
|
});
|