Add new test

This commit is contained in:
Zachary Eisinger 2019-11-05 15:28:47 -08:00
parent 5668f1310e
commit 173f136494
5 changed files with 56 additions and 17 deletions

View File

@ -8,6 +8,7 @@ const toolDir = path.join(__dirname, 'runner', 'tools');
const tempDir = path.join(__dirname, 'runner', 'temp'); const tempDir = path.join(__dirname, 'runner', 'temp');
process.env['RUNNER_TOOL_CACHE'] = toolDir; process.env['RUNNER_TOOL_CACHE'] = toolDir;
process.env['DOTNET_INSTALL_DIR'] = toolDir;
process.env['RUNNER_TEMP'] = tempDir; process.env['RUNNER_TEMP'] = tempDir;
import * as installer from '../src/installer'; import * as installer from '../src/installer';
@ -30,7 +31,7 @@ describe('installer tests', () => {
it('Acquires version of dotnet if no matching version is installed', async () => { it('Acquires version of dotnet if no matching version is installed', async () => {
await getDotnet('2.2.104'); await getDotnet('2.2.104');
const dotnetDir = path.join(toolDir, 'dncs', '2.2.104', os.arch()); const dotnetDir = path.join(toolDir);
expect(fs.existsSync(`${dotnetDir}.complete`)).toBe(true); expect(fs.existsSync(`${dotnetDir}.complete`)).toBe(true);
if (IS_WINDOWS) { if (IS_WINDOWS) {
@ -59,20 +60,6 @@ describe('installer tests', () => {
return; return;
}); });
it('Doesnt use version of dotnet that was only partially installed in cache', async () => {
const dotnetDir: string = path.join(toolDir, 'dncs', '251.0.0', os.arch());
await io.mkdirP(dotnetDir);
let thrown = false;
try {
// This will throw if it doesn't find it in the cache (because no such version exists)
await getDotnet('251.0.0');
} catch {
thrown = true;
}
expect(thrown).toBe(true);
return;
});
it('Uses an up to date bash download script', async () => { it('Uses an up to date bash download script', async () => {
var httpCallbackClient = new httpClient.HttpClient( var httpCallbackClient = new httpClient.HttpClient(
'setup-dotnet-test', 'setup-dotnet-test',

View File

@ -0,0 +1,51 @@
import io = require('@actions/io');
import fs = require('fs');
import os = require('os');
import path = require('path');
import httpClient = require('typed-rest-client/HttpClient');
const toolDir = path.join(__dirname, 'runner', 'tools');
const tempDir = path.join(__dirname, 'runner', 'temp');
import * as setup from '../src/setup-dotnet';
const IS_WINDOWS = process.platform === 'win32';
describe('setup-dotnet tests', () => {
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);
});
afterAll(async () => {
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');
}
}, 100000);
it('Acquires version of dotnet if no matching version is installed', async () => {
const dotnetDir = path.join(toolDir, 'dncs', '2.2.105', os.arch());
const globalJsonPath = path.join(process.cwd(), 'global.json');
const jsonContents = `{${os.EOL}"sdk": {${os.EOL}"version": "2.2.105"${os.EOL}}${os.EOL}}`;
if (!fs.existsSync(globalJsonPath)) {
fs.writeFileSync(globalJsonPath, jsonContents);
}
await setup.run();
expect(fs.existsSync(`${dotnetDir}.complete`)).toBe(true);
if (IS_WINDOWS) {
expect(fs.existsSync(path.join(dotnetDir, 'dotnet.exe'))).toBe(true);
} else {
expect(fs.existsSync(path.join(dotnetDir, 'dotnet'))).toBe(true);
}
fs.unlinkSync(globalJsonPath);
}, 100000);
});

View File

@ -23,7 +23,7 @@ const path = __importStar(require("path"));
const semver = __importStar(require("semver")); const semver = __importStar(require("semver"));
const IS_WINDOWS = process.platform === 'win32'; const IS_WINDOWS = process.platform === 'win32';
class DotnetCoreInstaller { class DotnetCoreInstaller {
constructor(version = "", jsonfile = "") { constructor(version = '', jsonfile = '') {
if (semver.valid(semver.clean(version) || '') == null) { if (semver.valid(semver.clean(version) || '') == null) {
throw 'Implicit version not permitted'; throw 'Implicit version not permitted';
} }

View File

@ -50,4 +50,5 @@ function run() {
} }
}); });
} }
exports.run = run;
run(); run();

View File

@ -3,7 +3,7 @@ import * as installer from './installer';
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
async function run() { export async function run() {
try { try {
// //
// Version is optional. If supplied, install / use from the tool cache // Version is optional. If supplied, install / use from the tool cache