mirror of
				https://github.com/actions/setup-dotnet.git
				synced 2025-10-31 23:23:46 +00:00 
			
		
		
		
	* 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>
		
			
				
	
	
		
			123 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			123 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import * as cache from '@actions/cache';
 | |
| import * as exec from '@actions/exec';
 | |
| 
 | |
| import {getNuGetFolderPath, isCacheFeatureAvailable} from '../src/cache-utils';
 | |
| 
 | |
| jest.mock('@actions/cache');
 | |
| jest.mock('@actions/core');
 | |
| jest.mock('@actions/exec');
 | |
| 
 | |
| describe('cache-utils tests', () => {
 | |
|   describe('getNuGetFolderPath()', () => {
 | |
|     it.each([
 | |
|       [
 | |
|         `
 | |
| http-cache: /home/codespace/.local/share/NuGet/v3-cache
 | |
| global-packages: /var/nuget
 | |
| temp: /tmp/NuGetScratch
 | |
| plugins-cache: /home/codespace/.local/share/NuGet/plugins-cache
 | |
| `,
 | |
|         {
 | |
|           'http-cache': '/home/codespace/.local/share/NuGet/v3-cache',
 | |
|           'global-packages': '/var/nuget',
 | |
|           temp: '/tmp/NuGetScratch',
 | |
|           'plugins-cache': '/home/codespace/.local/share/NuGet/plugins-cache'
 | |
|         }
 | |
|       ],
 | |
|       [
 | |
|         `
 | |
|   http-cache: /home/codespace/.local/share/NuGet/v3-cache
 | |
|   global-packages: /var/nuget
 | |
|   temp: /tmp/NuGetScratch
 | |
|   plugins-cache: /home/codespace/.local/share/NuGet/plugins-cache
 | |
| `,
 | |
|         {
 | |
|           'http-cache': '/home/codespace/.local/share/NuGet/v3-cache',
 | |
|           'global-packages': '/var/nuget',
 | |
|           temp: '/tmp/NuGetScratch',
 | |
|           'plugins-cache': '/home/codespace/.local/share/NuGet/plugins-cache'
 | |
|         }
 | |
|       ],
 | |
|       [
 | |
|         `
 | |
| http-cache: C:\\Users\\user\\AppData\\Local\\NuGet\\v3-cache
 | |
| global-packages: C:\\Users\\user\\.nuget\\packages\\
 | |
| temp: C:\\Users\\user\\AppData\\Local\\Temp\\NuGetScratch
 | |
| plugins-cache: C:\\Users\\user\\AppData\\Local\\NuGet\\plugins-cache
 | |
|         `,
 | |
|         {
 | |
|           'http-cache': 'C:\\Users\\user\\AppData\\Local\\NuGet\\v3-cache',
 | |
|           'global-packages': 'C:\\Users\\user\\.nuget\\packages\\',
 | |
|           temp: 'C:\\Users\\user\\AppData\\Local\\Temp\\NuGetScratch',
 | |
|           'plugins-cache':
 | |
|             'C:\\Users\\user\\AppData\\Local\\NuGet\\plugins-cache'
 | |
|         }
 | |
|       ],
 | |
|       [
 | |
|         `
 | |
|   http-cache: C:\\Users\\user\\AppData\\Local\\NuGet\\v3-cache
 | |
|   global-packages: C:\\Users\\user\\.nuget\\packages\\
 | |
|   temp: C:\\Users\\user\\AppData\\Local\\Temp\\NuGetScratch
 | |
|   plugins-cache: C:\\Users\\user\\AppData\\Local\\NuGet\\plugins-cache
 | |
|         `,
 | |
|         {
 | |
|           'http-cache': 'C:\\Users\\user\\AppData\\Local\\NuGet\\v3-cache',
 | |
|           'global-packages': 'C:\\Users\\user\\.nuget\\packages\\',
 | |
|           temp: 'C:\\Users\\user\\AppData\\Local\\Temp\\NuGetScratch',
 | |
|           'plugins-cache':
 | |
|             'C:\\Users\\user\\AppData\\Local\\NuGet\\plugins-cache'
 | |
|         }
 | |
|       ]
 | |
|     ])('(stdout: "%s") returns %p', async (stdout, expected) => {
 | |
|       jest
 | |
|         .mocked(exec.getExecOutput)
 | |
|         .mockResolvedValue({stdout, stderr: '', exitCode: 0});
 | |
|       const pathes = await getNuGetFolderPath();
 | |
|       expect(pathes).toStrictEqual(expected);
 | |
|     });
 | |
| 
 | |
|     it.each([
 | |
|       `
 | |
| error: An invalid local resource name was provided. Provide one of the following values: http-cache, temp, global-packages, all.
 | |
| Usage: dotnet nuget locals [arguments] [options]
 | |
| Arguments:
 | |
|   Cache Location(s)  Specifies the cache location(s) to list or clear.
 | |
| <all | http-cache | global-packages | temp>
 | |
| Options:
 | |
|   -h|--help               Show help information
 | |
|   --force-english-output  Forces the application to run using an invariant, English-based culture.
 | |
|   -c|--clear              Clear the selected local resources or cache location(s).
 | |
|   -l|--list               List the selected local resources or cache location(s).
 | |
|       `,
 | |
|       'bash: dotnet: command not found',
 | |
|       ''
 | |
|     ])('(stderr: "%s", exitCode: 1) throws Error', async stderr => {
 | |
|       jest
 | |
|         .mocked(exec.getExecOutput)
 | |
|         .mockResolvedValue({stdout: '', stderr, exitCode: 1});
 | |
|       await expect(getNuGetFolderPath()).rejects.toThrow();
 | |
|     });
 | |
|   });
 | |
| 
 | |
|   describe.each(['', 'https://github.com/', 'https://example.com/'])(
 | |
|     'isCacheFeatureAvailable()',
 | |
|     url => {
 | |
|       // Save & Restore env
 | |
|       let serverUrlEnv: string | undefined;
 | |
|       beforeAll(() => (serverUrlEnv = process.env['GITHUB_SERVER_URL']));
 | |
|       beforeEach(() => (process.env['GITHUB_SERVER_URL'] = url));
 | |
|       afterEach(() => (process.env['GITHUB_SERVER_URL'] = serverUrlEnv));
 | |
| 
 | |
|       it('returns true when cache.isFeatureAvailable() === true', () => {
 | |
|         jest.mocked(cache.isFeatureAvailable).mockReturnValue(true);
 | |
|         expect(isCacheFeatureAvailable()).toBe(true);
 | |
|       });
 | |
| 
 | |
|       it('returns false when cache.isFeatureAvailable() === false', () => {
 | |
|         jest.mocked(cache.isFeatureAvailable).mockReturnValue(false);
 | |
|         expect(isCacheFeatureAvailable()).toBe(false);
 | |
|       });
 | |
|     }
 | |
|   );
 | |
| });
 |