mirror of
https://github.com/actions/setup-dotnet.git
synced 2025-04-06 23:39:47 +00:00
Merge remote-tracking branch 'github/main' into refactor-installer
This commit is contained in:
@ -5,12 +5,15 @@ import * as auth from '../src/authutil';
|
||||
|
||||
import * as setup from '../src/setup-dotnet';
|
||||
import {DotnetCoreInstaller, DotnetInstallDir} from '../src/installer';
|
||||
import * as cacheUtils from '../src/cache-utils';
|
||||
import * as cacheRestore from '../src/cache-restore';
|
||||
|
||||
describe('setup-dotnet tests', () => {
|
||||
const inputs = {} as any;
|
||||
|
||||
const getInputSpy = jest.spyOn(core, 'getInput');
|
||||
const getMultilineInputSpy = jest.spyOn(core, 'getMultilineInput');
|
||||
const getBooleanInputSpy = jest.spyOn(core, 'getBooleanInput');
|
||||
const setFailedSpy = jest.spyOn(core, 'setFailed');
|
||||
const warningSpy = jest.spyOn(core, 'warning');
|
||||
const debugSpy = jest.spyOn(core, 'debug');
|
||||
@ -26,6 +29,11 @@ describe('setup-dotnet tests', () => {
|
||||
'installDotnet'
|
||||
);
|
||||
|
||||
const isCacheFeatureAvailableSpy = jest.spyOn(
|
||||
cacheUtils,
|
||||
'isCacheFeatureAvailable'
|
||||
);
|
||||
const restoreCacheSpy = jest.spyOn(cacheRestore, 'restoreCache');
|
||||
const configAuthenticationSpy = jest.spyOn(auth, 'configAuthentication');
|
||||
const addToPathOriginal = DotnetInstallDir.addToPath;
|
||||
|
||||
@ -34,6 +42,7 @@ describe('setup-dotnet tests', () => {
|
||||
DotnetInstallDir.addToPath = jest.fn();
|
||||
getMultilineInputSpy.mockImplementation(input => inputs[input as string]);
|
||||
getInputSpy.mockImplementation(input => inputs[input as string]);
|
||||
getBooleanInputSpy.mockImplementation(input => inputs[input as string]);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@ -166,5 +175,51 @@ describe('setup-dotnet tests', () => {
|
||||
expect(infoSpy).toHaveBeenCalledWith(warningMessage);
|
||||
expect(setOutputSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it(`should get 'cache-dependency-path' and call restoreCache() if input cache is set to true and cache feature is available`, async () => {
|
||||
inputs['dotnet-version'] = ['6.0.300'];
|
||||
inputs['dotnet-quality'] = '';
|
||||
inputs['cache'] = true;
|
||||
inputs['cache-dependency-path'] = 'fictitious.package.lock.json';
|
||||
|
||||
installDotnetSpy.mockImplementation(() => Promise.resolve(''));
|
||||
|
||||
isCacheFeatureAvailableSpy.mockImplementation(() => true);
|
||||
restoreCacheSpy.mockImplementation(() => Promise.resolve());
|
||||
|
||||
await setup.run();
|
||||
expect(isCacheFeatureAvailableSpy).toHaveBeenCalledTimes(1);
|
||||
expect(restoreCacheSpy).toHaveBeenCalledWith(
|
||||
inputs['cache-dependency-path']
|
||||
);
|
||||
});
|
||||
|
||||
it(`shouldn't call restoreCache() if input cache isn't set to true`, async () => {
|
||||
inputs['dotnet-version'] = ['6.0.300'];
|
||||
inputs['dotnet-quality'] = '';
|
||||
inputs['cache'] = false;
|
||||
|
||||
installDotnetSpy.mockImplementation(() => Promise.resolve(''));
|
||||
|
||||
isCacheFeatureAvailableSpy.mockImplementation(() => true);
|
||||
restoreCacheSpy.mockImplementation(() => Promise.resolve());
|
||||
|
||||
await setup.run();
|
||||
expect(restoreCacheSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it(`shouldn't call restoreCache() if cache feature isn't available`, async () => {
|
||||
inputs['dotnet-version'] = ['6.0.300'];
|
||||
inputs['dotnet-quality'] = '';
|
||||
inputs['cache'] = true;
|
||||
|
||||
installDotnetSpy.mockImplementation(() => Promise.resolve(''));
|
||||
|
||||
isCacheFeatureAvailableSpy.mockImplementation(() => false);
|
||||
restoreCacheSpy.mockImplementation(() => Promise.resolve());
|
||||
|
||||
await setup.run();
|
||||
expect(restoreCacheSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user