mirror of
				https://github.com/actions/cache.git
				synced 2025-10-31 14:30:54 +00:00 
			
		
		
		
	Add lookup-only option (#1041)
		
	* Add new actions/cache version (with dryRun support) * Add dry-run option * Changes after rebase * Update readme * Rename option to lookup-only * Update test name * Update package.json + changelog * Update README * Update custom package version * Update custom package version * Update @actions/cache to 3.2.0 * Code review * Update log statement * Move test case --------- Co-authored-by: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com>
This commit is contained in:
		
					parent
					
						
							
								e0d62270e2
							
						
					
				
			
			
				commit
				
					
						940f3d7cf1
					
				
			
		
					 18 changed files with 260 additions and 47 deletions
				
			
		|  | @ -122,7 +122,15 @@ test("restore on GHES with AC available ", async () => { | |||
|     await run(new StateProvider()); | ||||
| 
 | ||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); | ||||
|     expect(restoreCacheMock).toHaveBeenCalledWith( | ||||
|         [path], | ||||
|         key, | ||||
|         [], | ||||
|         { | ||||
|             lookupOnly: false | ||||
|         }, | ||||
|         false | ||||
|     ); | ||||
| 
 | ||||
|     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); | ||||
|     expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); | ||||
|  | @ -172,7 +180,9 @@ test("restore with too many keys should fail", async () => { | |||
|         [path], | ||||
|         key, | ||||
|         restoreKeys, | ||||
|         {}, | ||||
|         { | ||||
|             lookupOnly: false | ||||
|         }, | ||||
|         false | ||||
|     ); | ||||
|     expect(failedMock).toHaveBeenCalledWith( | ||||
|  | @ -192,7 +202,15 @@ test("restore with large key should fail", async () => { | |||
|     const restoreCacheMock = jest.spyOn(cache, "restoreCache"); | ||||
|     await run(new StateProvider()); | ||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); | ||||
|     expect(restoreCacheMock).toHaveBeenCalledWith( | ||||
|         [path], | ||||
|         key, | ||||
|         [], | ||||
|         { | ||||
|             lookupOnly: false | ||||
|         }, | ||||
|         false | ||||
|     ); | ||||
|     expect(failedMock).toHaveBeenCalledWith( | ||||
|         `Key Validation Error: ${key} cannot be larger than 512 characters.` | ||||
|     ); | ||||
|  | @ -210,7 +228,15 @@ test("restore with invalid key should fail", async () => { | |||
|     const restoreCacheMock = jest.spyOn(cache, "restoreCache"); | ||||
|     await run(new StateProvider()); | ||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); | ||||
|     expect(restoreCacheMock).toHaveBeenCalledWith( | ||||
|         [path], | ||||
|         key, | ||||
|         [], | ||||
|         { | ||||
|             lookupOnly: false | ||||
|         }, | ||||
|         false | ||||
|     ); | ||||
|     expect(failedMock).toHaveBeenCalledWith( | ||||
|         `Key Validation Error: ${key} cannot contain commas.` | ||||
|     ); | ||||
|  | @ -237,7 +263,15 @@ test("restore with no cache found", async () => { | |||
|     await run(new StateProvider()); | ||||
| 
 | ||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); | ||||
|     expect(restoreCacheMock).toHaveBeenCalledWith( | ||||
|         [path], | ||||
|         key, | ||||
|         [], | ||||
|         { | ||||
|             lookupOnly: false | ||||
|         }, | ||||
|         false | ||||
|     ); | ||||
| 
 | ||||
|     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); | ||||
|     expect(failedMock).toHaveBeenCalledTimes(0); | ||||
|  | @ -274,7 +308,9 @@ test("restore with restore keys and no cache found", async () => { | |||
|         [path], | ||||
|         key, | ||||
|         [restoreKey], | ||||
|         {}, | ||||
|         { | ||||
|             lookupOnly: false | ||||
|         }, | ||||
|         false | ||||
|     ); | ||||
| 
 | ||||
|  | @ -308,7 +344,15 @@ test("restore with cache found for key", async () => { | |||
|     await run(new StateProvider()); | ||||
| 
 | ||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); | ||||
|     expect(restoreCacheMock).toHaveBeenCalledWith( | ||||
|         [path], | ||||
|         key, | ||||
|         [], | ||||
|         { | ||||
|             lookupOnly: false | ||||
|         }, | ||||
|         false | ||||
|     ); | ||||
| 
 | ||||
|     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); | ||||
|     expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); | ||||
|  | @ -346,7 +390,9 @@ test("restore with cache found for restore key", async () => { | |||
|         [path], | ||||
|         key, | ||||
|         [restoreKey], | ||||
|         {}, | ||||
|         { | ||||
|             lookupOnly: false | ||||
|         }, | ||||
|         false | ||||
|     ); | ||||
| 
 | ||||
|  | @ -358,3 +404,48 @@ test("restore with cache found for restore key", async () => { | |||
|     ); | ||||
|     expect(failedMock).toHaveBeenCalledTimes(0); | ||||
| }); | ||||
| 
 | ||||
| test("restore with lookup-only set", async () => { | ||||
|     const path = "node_modules"; | ||||
|     const key = "node-test"; | ||||
|     testUtils.setInputs({ | ||||
|         path: path, | ||||
|         key, | ||||
|         lookupOnly: true | ||||
|     }); | ||||
| 
 | ||||
|     const infoMock = jest.spyOn(core, "info"); | ||||
|     const failedMock = jest.spyOn(core, "setFailed"); | ||||
|     const stateMock = jest.spyOn(core, "saveState"); | ||||
|     const setCacheHitOutputMock = jest.spyOn(core, "setOutput"); | ||||
|     const restoreCacheMock = jest | ||||
|         .spyOn(cache, "restoreCache") | ||||
|         .mockImplementationOnce(() => { | ||||
|             return Promise.resolve(key); | ||||
|         }); | ||||
| 
 | ||||
|     await run(new StateProvider()); | ||||
| 
 | ||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||
|     expect(restoreCacheMock).toHaveBeenCalledWith( | ||||
|         [path], | ||||
|         key, | ||||
|         [], | ||||
|         { | ||||
|             lookupOnly: true | ||||
|         }, | ||||
|         false | ||||
|     ); | ||||
| 
 | ||||
|     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); | ||||
|     expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key); | ||||
|     expect(stateMock).toHaveBeenCalledTimes(2); | ||||
| 
 | ||||
|     expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); | ||||
|     expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true"); | ||||
| 
 | ||||
|     expect(infoMock).toHaveBeenCalledWith( | ||||
|         `Cache found and can be restored from key: ${key}` | ||||
|     ); | ||||
|     expect(failedMock).toHaveBeenCalledTimes(0); | ||||
| }); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue