mirror of
https://github.com/actions/setup-dotnet.git
synced 2024-11-22 11:31:07 +07:00
Update tests
This commit is contained in:
parent
89b480a0df
commit
427804d76a
@ -283,14 +283,14 @@ describe('installer tests', () => {
|
|||||||
describe('addToPath() tests', () => {
|
describe('addToPath() tests', () => {
|
||||||
it(`should export DOTNET_ROOT env.var with value from DOTNET_INSTALL_DIR env.var`, async () => {
|
it(`should export DOTNET_ROOT env.var with value from DOTNET_INSTALL_DIR env.var`, async () => {
|
||||||
process.env['DOTNET_INSTALL_DIR'] = 'fictitious/dotnet/install/dir';
|
process.env['DOTNET_INSTALL_DIR'] = 'fictitious/dotnet/install/dir';
|
||||||
installer.DotnetCoreInstaller.addToPath();
|
installer.DotnetInstallDir.addToPath();
|
||||||
const dotnet_root = process.env['DOTNET_ROOT'];
|
const dotnet_root = process.env['DOTNET_ROOT'];
|
||||||
expect(dotnet_root).toBe(process.env['DOTNET_INSTALL_DIR']);
|
expect(dotnet_root).toBe(process.env['DOTNET_INSTALL_DIR']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should export value from DOTNET_INSTALL_DIR env.var to the PATH`, async () => {
|
it(`should export value from DOTNET_INSTALL_DIR env.var to the PATH`, async () => {
|
||||||
process.env['DOTNET_INSTALL_DIR'] = 'fictitious/dotnet/install/dir';
|
process.env['DOTNET_INSTALL_DIR'] = 'fictitious/dotnet/install/dir';
|
||||||
installer.DotnetCoreInstaller.addToPath();
|
installer.DotnetInstallDir.addToPath();
|
||||||
const path = process.env['PATH'];
|
const path = process.env['PATH'];
|
||||||
expect(path).toContain(process.env['DOTNET_INSTALL_DIR']);
|
expect(path).toContain(process.env['DOTNET_INSTALL_DIR']);
|
||||||
});
|
});
|
||||||
|
@ -4,7 +4,7 @@ import semver from 'semver';
|
|||||||
import * as auth from '../src/authutil';
|
import * as auth from '../src/authutil';
|
||||||
|
|
||||||
import * as setup from '../src/setup-dotnet';
|
import * as setup from '../src/setup-dotnet';
|
||||||
import {DotnetCoreInstaller} from '../src/installer';
|
import {DotnetCoreInstaller, DotnetInstallDir} from '../src/installer';
|
||||||
|
|
||||||
describe('setup-dotnet tests', () => {
|
describe('setup-dotnet tests', () => {
|
||||||
const inputs = {} as any;
|
const inputs = {} as any;
|
||||||
@ -25,17 +25,19 @@ describe('setup-dotnet tests', () => {
|
|||||||
DotnetCoreInstaller.prototype,
|
DotnetCoreInstaller.prototype,
|
||||||
'installDotnet'
|
'installDotnet'
|
||||||
);
|
);
|
||||||
const addToPathSpy = jest.spyOn(DotnetCoreInstaller, 'addToPath');
|
|
||||||
|
|
||||||
const configAuthenticationSpy = jest.spyOn(auth, 'configAuthentication');
|
const configAuthenticationSpy = jest.spyOn(auth, 'configAuthentication');
|
||||||
|
const addToPathOriginal = DotnetInstallDir.addToPath;
|
||||||
|
|
||||||
describe('run() tests', () => {
|
describe('run() tests', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
DotnetInstallDir.addToPath = jest.fn();
|
||||||
getMultilineInputSpy.mockImplementation(input => inputs[input as string]);
|
getMultilineInputSpy.mockImplementation(input => inputs[input as string]);
|
||||||
getInputSpy.mockImplementation(input => inputs[input as string]);
|
getInputSpy.mockImplementation(input => inputs[input as string]);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
DotnetInstallDir.addToPath = addToPathOriginal;
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
});
|
});
|
||||||
@ -96,10 +98,9 @@ describe('setup-dotnet tests', () => {
|
|||||||
inputs['dotnet-quality'] = '';
|
inputs['dotnet-quality'] = '';
|
||||||
|
|
||||||
installDotnetSpy.mockImplementation(() => Promise.resolve(''));
|
installDotnetSpy.mockImplementation(() => Promise.resolve(''));
|
||||||
addToPathSpy.mockImplementation(() => {});
|
|
||||||
|
|
||||||
await setup.run();
|
await setup.run();
|
||||||
expect(addToPathSpy).toHaveBeenCalledTimes(1);
|
expect(DotnetInstallDir.addToPath).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call auth.configAuthentication() if source-url input is provided', async () => {
|
it('should call auth.configAuthentication() if source-url input is provided', async () => {
|
||||||
@ -140,10 +141,9 @@ describe('setup-dotnet tests', () => {
|
|||||||
installDotnetSpy.mockImplementation(() =>
|
installDotnetSpy.mockImplementation(() =>
|
||||||
Promise.resolve(`${inputs['dotnet-version']}`)
|
Promise.resolve(`${inputs['dotnet-version']}`)
|
||||||
);
|
);
|
||||||
addToPathSpy.mockImplementation(() => {});
|
|
||||||
|
|
||||||
await setup.run();
|
await setup.run();
|
||||||
expect(setOutputSpy).toHaveBeenCalledTimes(1);
|
expect(DotnetInstallDir.addToPath).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`shouldn't call setOutput() if parsing dotnet-installer logs failed`, async () => {
|
it(`shouldn't call setOutput() if parsing dotnet-installer logs failed`, async () => {
|
||||||
@ -151,7 +151,6 @@ describe('setup-dotnet tests', () => {
|
|||||||
const warningMessage = `Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.`;
|
const warningMessage = `Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.`;
|
||||||
|
|
||||||
installDotnetSpy.mockImplementation(() => Promise.resolve(null));
|
installDotnetSpy.mockImplementation(() => Promise.resolve(null));
|
||||||
addToPathSpy.mockImplementation(() => {});
|
|
||||||
|
|
||||||
await setup.run();
|
await setup.run();
|
||||||
expect(warningSpy).toHaveBeenCalledWith(warningMessage);
|
expect(warningSpy).toHaveBeenCalledWith(warningMessage);
|
||||||
@ -162,8 +161,6 @@ describe('setup-dotnet tests', () => {
|
|||||||
inputs['dotnet-version'] = [];
|
inputs['dotnet-version'] = [];
|
||||||
const warningMessage = `The 'dotnet-version' output will not be set.`;
|
const warningMessage = `The 'dotnet-version' output will not be set.`;
|
||||||
|
|
||||||
addToPathSpy.mockImplementation(() => {});
|
|
||||||
|
|
||||||
await setup.run();
|
await setup.run();
|
||||||
|
|
||||||
expect(infoSpy).toHaveBeenCalledWith(warningMessage);
|
expect(infoSpy).toHaveBeenCalledWith(warningMessage);
|
||||||
|
Loading…
Reference in New Issue
Block a user