mirror of
https://github.com/actions/setup-dotnet.git
synced 2025-08-18 14:45:09 +00:00
Add unit-tests
This commit is contained in:
parent
6eb9549b62
commit
68d994cec2
@ -107,6 +107,15 @@ describe('DotnetCoreInstaller tests', () => {
|
|||||||
expect(process.env.PATH?.startsWith(toolDir)).toBe(true);
|
expect(process.env.PATH?.startsWith(toolDir)).toBe(true);
|
||||||
}, 600000); //This needs some time to download on "slower" internet connections
|
}, 600000); //This needs some time to download on "slower" internet connections
|
||||||
|
|
||||||
|
it('Returns string with installed SDK version', async () => {
|
||||||
|
const version = '3.1.120';
|
||||||
|
let installedVersion: string;
|
||||||
|
|
||||||
|
installedVersion = await getDotnet(version);
|
||||||
|
|
||||||
|
expect(installedVersion).toBe('3.1.120');
|
||||||
|
}, 600000);
|
||||||
|
|
||||||
it('Throws if no location contains correct dotnet version', async () => {
|
it('Throws if no location contains correct dotnet version', async () => {
|
||||||
await expect(async () => {
|
await expect(async () => {
|
||||||
await getDotnet('1000.0.0');
|
await getDotnet('1000.0.0');
|
||||||
@ -267,11 +276,15 @@ function normalizeFileContents(contents: string): string {
|
|||||||
.replace(new RegExp('\r', 'g'), '\n');
|
.replace(new RegExp('\r', 'g'), '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getDotnet(version: string, quality: string = ''): Promise<void> {
|
async function getDotnet(
|
||||||
|
version: string,
|
||||||
|
quality: string = ''
|
||||||
|
): Promise<string> {
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
const dotnetInstaller = new installer.DotnetCoreInstaller(
|
||||||
version,
|
version,
|
||||||
quality as QualityOptions
|
quality as QualityOptions
|
||||||
);
|
);
|
||||||
await dotnetInstaller.installDotnet();
|
const installedVersion = await dotnetInstaller.installDotnet();
|
||||||
installer.DotnetCoreInstaller.addToPath();
|
installer.DotnetCoreInstaller.addToPath();
|
||||||
|
return installedVersion;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import * as io from '@actions/io';
|
import * as io from '@actions/io';
|
||||||
|
import * as core from '@actions/core';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
@ -20,6 +21,8 @@ if (IS_WINDOWS) {
|
|||||||
const tempDir = path.join(__dirname, 'runner', 'temp2');
|
const tempDir = path.join(__dirname, 'runner', 'temp2');
|
||||||
|
|
||||||
describe('setup-dotnet tests', () => {
|
describe('setup-dotnet tests', () => {
|
||||||
|
let getMultilineInputSpy = jest.spyOn(core, 'getMultilineInput');
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
process.env.RUNNER_TOOL_CACHE = toolDir;
|
process.env.RUNNER_TOOL_CACHE = toolDir;
|
||||||
process.env.DOTNET_INSTALL_DIR = toolDir;
|
process.env.DOTNET_INSTALL_DIR = toolDir;
|
||||||
@ -59,4 +62,18 @@ describe('setup-dotnet tests', () => {
|
|||||||
expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
|
expect(fs.existsSync(path.join(toolDir, 'dotnet'))).toBe(true);
|
||||||
}
|
}
|
||||||
}, 400000);
|
}, 400000);
|
||||||
|
|
||||||
|
it('Sets output with the installed version', async () => {
|
||||||
|
const versions = ['3.1.201', '6.0.401'];
|
||||||
|
|
||||||
|
let setOutputSpy = jest.spyOn(core, 'getMultilineInput');
|
||||||
|
|
||||||
|
getMultilineInputSpy.mockImplementation(() => {
|
||||||
|
return versions;
|
||||||
|
});
|
||||||
|
|
||||||
|
await setup.run();
|
||||||
|
|
||||||
|
expect(setOutputSpy).toBeCalledWith('dotnet-version', '3.1.201');
|
||||||
|
}, 400000);
|
||||||
});
|
});
|
||||||
|
@ -164,7 +164,7 @@ export class DotnetCoreInstaller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async installDotnet() {
|
public async installDotnet(): Promise<string> {
|
||||||
const windowsDefaultOptions = [
|
const windowsDefaultOptions = [
|
||||||
'-NoLogo',
|
'-NoLogo',
|
||||||
'-Sta',
|
'-Sta',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user