2020-09-16 00:36:09 +08:00
|
|
|
import io = require('@actions/io');
|
|
|
|
import fs = require('fs');
|
|
|
|
import os = require('os');
|
|
|
|
import path = require('path');
|
|
|
|
|
|
|
|
const toolDir = path.join(__dirname, 'runner', 'tools2');
|
|
|
|
const tempDir = path.join(__dirname, 'runner', 'temp2');
|
|
|
|
|
|
|
|
import * as setup from '../src/setup-dotnet';
|
2021-08-20 22:11:48 +08:00
|
|
|
import * as dotnetInstaller from '../src/installer';
|
2020-09-16 00:36:09 +08:00
|
|
|
|
|
|
|
const IS_WINDOWS = process.platform === 'win32';
|
|
|
|
|
2021-08-20 21:47:49 +08:00
|
|
|
describe('setup-dotnet tests', () => {
|
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;
|
|
|
|
await io.rmRF(toolDir);
|
|
|
|
await io.rmRF(tempDir);
|
|
|
|
});
|
|
|
|
|
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'));
|
|
|
|
await io.rmRF(toolDir);
|
|
|
|
await io.rmRF(tempDir);
|
|
|
|
} catch {
|
|
|
|
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);
|
2021-08-20 20:43:49 +08:00
|
|
|
|
2021-08-20 21:47:49 +08:00
|
|
|
it('Acquires version of dotnet from global.json with rollForward option, install the latest patch', async () => {
|
2021-08-20 20:43:49 +08:00
|
|
|
const globalJsonPath = path.join(process.cwd(), 'global.json');
|
2021-08-20 21:35:44 +08:00
|
|
|
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version":"3.1.201",${os.EOL}"rollForward":"latestFeature"${os.EOL}}${os.EOL}}`;
|
2021-08-20 20:43:49 +08:00
|
|
|
if (!fs.existsSync(globalJsonPath)) {
|
|
|
|
fs.writeFileSync(globalJsonPath, jsonContents);
|
|
|
|
}
|
2021-08-20 22:11:48 +08:00
|
|
|
|
|
|
|
const version = '3.1'
|
|
|
|
const installer = new dotnetInstaller.DotnetCoreInstaller(version)
|
|
|
|
const patchVersion = await installer.resolveVersion(new dotnetInstaller.DotNetVersionInfo(version))
|
2021-08-20 20:43:49 +08:00
|
|
|
await setup.run();
|
|
|
|
|
2021-08-20 22:11:48 +08:00
|
|
|
expect(fs.existsSync(path.join(toolDir, 'sdk', patchVersion))).toBe(true);
|
2021-08-20 20:43:49 +08:00
|
|
|
if (IS_WINDOWS) {
|
|
|
|
expect(fs.existsSync(path.join(toolDir, 'dotnet.exe'))).toBe(true);
|
|
|
|
} else {
|
|
|
|
expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
|
|
|
|
}
|
|
|
|
}, 400000);
|
2020-09-16 00:36:09 +08:00
|
|
|
});
|