mirror of
https://github.com/actions/setup-dotnet.git
synced 2025-04-07 15:59:50 +00:00
feat: Cache NuGet global-packages folder (#303)
* feat: cache NuGet global-packages folder * fix: remove unused files * docs: fix incorrect action * ci: add e2e test for cache * docs: accept suggested changes on README * docs: add simple cache example * build: change main script path * fix: change relative path to install scripts * fix: change relative path to problem matcher * refactor: accept changes on cache-utils * fix: revert main script path changes * test: fix cache-utils unit test * test: fix cache-utils unit test * feat: add `cache-dependency-path` variables * build: change main script dist path * ci: add `cache-dependency-path` e2e test & missing lock file * fix: accept change suggestions * ci: copy NuGet lock file to root to pass "test-setup-with-cache" e2e test * docs: change README guide * fix: apply suggestions from code review Co-authored-by: Ivan <98037481+IvanZosimov@users.noreply.github.com> * test: fix some failed unit tests - fix `restoreCache()` test for 9703c8 - update installer script * build: rebuild dist * Update unit-tests - Additional unit test were added to setup-dotnet.test.ts * Update unit tests for unix systems * Format and lint unit tests * fix: avoid use '/' on `path.join` * fix: rebuild dist * fix: apply suggestions from code review Co-authored-by: Ivan <98037481+IvanZosimov@users.noreply.github.com> * build: add `DisableImplicitNuGetFallbackFolder` option also add guide on README * docs: highlight warnings and notes * docs: update note about handling NU1403 --------- Co-authored-by: Ivan <98037481+IvanZosimov@users.noreply.github.com> Co-authored-by: IvanZosimov <ivanzosimov@github.com>
This commit is contained in:
@ -5,12 +5,15 @@ import * as auth from '../src/authutil';
|
||||
|
||||
import * as setup from '../src/setup-dotnet';
|
||||
import {DotnetCoreInstaller} 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,13 +29,18 @@ describe('setup-dotnet tests', () => {
|
||||
'installDotnet'
|
||||
);
|
||||
const addToPathSpy = jest.spyOn(DotnetCoreInstaller, 'addToPath');
|
||||
|
||||
const isCacheFeatureAvailableSpy = jest.spyOn(
|
||||
cacheUtils,
|
||||
'isCacheFeatureAvailable'
|
||||
);
|
||||
const restoreCacheSpy = jest.spyOn(cacheRestore, 'restoreCache');
|
||||
const configAuthenticationSpy = jest.spyOn(auth, 'configAuthentication');
|
||||
|
||||
describe('run() tests', () => {
|
||||
beforeEach(() => {
|
||||
getMultilineInputSpy.mockImplementation(input => inputs[input as string]);
|
||||
getInputSpy.mockImplementation(input => inputs[input as string]);
|
||||
getBooleanInputSpy.mockImplementation(input => inputs[input as string]);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@ -169,5 +177,54 @@ 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(''));
|
||||
addToPathSpy.mockImplementation(() => {});
|
||||
|
||||
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(''));
|
||||
addToPathSpy.mockImplementation(() => {});
|
||||
|
||||
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(''));
|
||||
addToPathSpy.mockImplementation(() => {});
|
||||
|
||||
isCacheFeatureAvailableSpy.mockImplementation(() => false);
|
||||
restoreCacheSpy.mockImplementation(() => Promise.resolve());
|
||||
|
||||
await setup.run();
|
||||
expect(restoreCacheSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user