mirror of
				https://github.com/actions/cache.git
				synced 2025-10-31 18:34:19 +08:00 
			
		
		
		
	Fixed test cases
This commit is contained in:
		
							parent
							
								
									6f77edac15
								
							
						
					
					
						commit
						782b0bd3df
					
				| @ -1,7 +1,7 @@ | |||||||
| import * as cache from "@actions/cache"; | import * as cache from "@actions/cache"; | ||||||
| import * as core from "@actions/core"; | import * as core from "@actions/core"; | ||||||
| 
 | 
 | ||||||
| import { Events, Outputs, RefKey, State } from "../src/constants"; | import { Events, RefKey } from "../src/constants"; | ||||||
| import * as actionUtils from "../src/utils/actionUtils"; | import * as actionUtils from "../src/utils/actionUtils"; | ||||||
| import * as testUtils from "../src/utils/testUtils"; | import * as testUtils from "../src/utils/testUtils"; | ||||||
| 
 | 
 | ||||||
| @ -79,83 +79,6 @@ test("isExactKeyMatch with same key and different casing returns true", () => { | |||||||
|     expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(true); |     expect(actionUtils.isExactKeyMatch(key, cacheKey)).toBe(true); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test("setOutputAndState with undefined entry to set cache-hit output", () => { |  | ||||||
|     const key = "linux-rust"; |  | ||||||
|     const cacheKey = undefined; |  | ||||||
| 
 |  | ||||||
|     const setOutputMock = jest.spyOn(core, "setOutput"); |  | ||||||
|     const saveStateMock = jest.spyOn(core, "saveState"); |  | ||||||
| 
 |  | ||||||
|     actionUtils.setOutputAndState(key, cacheKey); |  | ||||||
| 
 |  | ||||||
|     expect(setOutputMock).toHaveBeenCalledWith(Outputs.CacheHit, "false"); |  | ||||||
|     expect(setOutputMock).toHaveBeenCalledTimes(1); |  | ||||||
| 
 |  | ||||||
|     expect(saveStateMock).toHaveBeenCalledTimes(0); |  | ||||||
| }); |  | ||||||
| 
 |  | ||||||
| test("setOutputAndState with exact match to set cache-hit output and state", () => { |  | ||||||
|     const key = "linux-rust"; |  | ||||||
|     const cacheKey = "linux-rust"; |  | ||||||
| 
 |  | ||||||
|     const setOutputMock = jest.spyOn(core, "setOutput"); |  | ||||||
|     const saveStateMock = jest.spyOn(core, "saveState"); |  | ||||||
| 
 |  | ||||||
|     actionUtils.setOutputAndState(key, cacheKey); |  | ||||||
| 
 |  | ||||||
|     expect(setOutputMock).toHaveBeenCalledWith(Outputs.CacheHit, "true"); |  | ||||||
|     expect(setOutputMock).toHaveBeenCalledTimes(1); |  | ||||||
| 
 |  | ||||||
|     expect(saveStateMock).toHaveBeenCalledWith(State.CacheMatchedKey, cacheKey); |  | ||||||
|     expect(saveStateMock).toHaveBeenCalledTimes(1); |  | ||||||
| }); |  | ||||||
| 
 |  | ||||||
| test("setOutputAndState with no exact match to set cache-hit output and state", () => { |  | ||||||
|     const key = "linux-rust"; |  | ||||||
|     const cacheKey = "linux-rust-bb828da54c148048dd17899ba9fda624811cfb43"; |  | ||||||
| 
 |  | ||||||
|     const setOutputMock = jest.spyOn(core, "setOutput"); |  | ||||||
|     const saveStateMock = jest.spyOn(core, "saveState"); |  | ||||||
| 
 |  | ||||||
|     actionUtils.setOutputAndState(key, cacheKey); |  | ||||||
| 
 |  | ||||||
|     expect(setOutputMock).toHaveBeenCalledWith(Outputs.CacheHit, "false"); |  | ||||||
|     expect(setOutputMock).toHaveBeenCalledTimes(1); |  | ||||||
| 
 |  | ||||||
|     expect(saveStateMock).toHaveBeenCalledWith(State.CacheMatchedKey, cacheKey); |  | ||||||
|     expect(saveStateMock).toHaveBeenCalledTimes(1); |  | ||||||
| }); |  | ||||||
| 
 |  | ||||||
| test("getCacheState with no state returns undefined", () => { |  | ||||||
|     const getStateMock = jest.spyOn(core, "getState"); |  | ||||||
|     getStateMock.mockImplementation(() => { |  | ||||||
|         return ""; |  | ||||||
|     }); |  | ||||||
| 
 |  | ||||||
|     const state = actionUtils.getCacheState(); |  | ||||||
| 
 |  | ||||||
|     expect(state).toBe(undefined); |  | ||||||
| 
 |  | ||||||
|     expect(getStateMock).toHaveBeenCalledWith(State.CacheMatchedKey); |  | ||||||
|     expect(getStateMock).toHaveBeenCalledTimes(1); |  | ||||||
| }); |  | ||||||
| 
 |  | ||||||
| test("getCacheState with valid state", () => { |  | ||||||
|     const cacheKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43"; |  | ||||||
| 
 |  | ||||||
|     const getStateMock = jest.spyOn(core, "getState"); |  | ||||||
|     getStateMock.mockImplementation(() => { |  | ||||||
|         return cacheKey; |  | ||||||
|     }); |  | ||||||
| 
 |  | ||||||
|     const state = actionUtils.getCacheState(); |  | ||||||
| 
 |  | ||||||
|     expect(state).toEqual(cacheKey); |  | ||||||
| 
 |  | ||||||
|     expect(getStateMock).toHaveBeenCalledWith(State.CacheMatchedKey); |  | ||||||
|     expect(getStateMock).toHaveBeenCalledTimes(1); |  | ||||||
| }); |  | ||||||
| 
 |  | ||||||
| test("logWarning logs a message with a warning prefix", () => { | test("logWarning logs a message with a warning prefix", () => { | ||||||
|     const message = "A warning occurred."; |     const message = "A warning occurred."; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -15,10 +15,6 @@ beforeAll(() => { | |||||||
|         return jest.requireActual("@actions/core").getInput(name, options); |         return jest.requireActual("@actions/core").getInput(name, options); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     jest.spyOn(actionUtils, "getCacheState").mockImplementation(() => { |  | ||||||
|         return jest.requireActual("../src/utils/actionUtils").getCacheState(); |  | ||||||
|     }); |  | ||||||
| 
 |  | ||||||
|     jest.spyOn(actionUtils, "getInputAsArray").mockImplementation( |     jest.spyOn(actionUtils, "getInputAsArray").mockImplementation( | ||||||
|         (name, options) => { |         (name, options) => { | ||||||
|             return jest |             return jest | ||||||
| @ -86,11 +82,11 @@ test("save with no primary key in state outputs warning", async () => { | |||||||
|     jest.spyOn(core, "getState") |     jest.spyOn(core, "getState") | ||||||
|         // Cache Entry State
 |         // Cache Entry State
 | ||||||
|         .mockImplementationOnce(() => { |         .mockImplementationOnce(() => { | ||||||
|             return savedCacheKey; |             return ""; | ||||||
|         }) |         }) | ||||||
|         // Cache Key State
 |         // Cache Key State
 | ||||||
|         .mockImplementationOnce(() => { |         .mockImplementationOnce(() => { | ||||||
|             return ""; |             return savedCacheKey; | ||||||
|         }); |         }); | ||||||
|     const saveCacheMock = jest.spyOn(cache, "saveCache"); |     const saveCacheMock = jest.spyOn(cache, "saveCache"); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Sankalp Kotewar
						Sankalp Kotewar