mirror of
				https://github.com/actions/cache.git
				synced 2025-11-01 02:44:18 +08:00 
			
		
		
		
	Address review comments and update tests
This commit is contained in:
		
							parent
							
								
									af9067e3c7
								
							
						
					
					
						commit
						2637f06e5f
					
				| @ -174,6 +174,26 @@ test("getInputAsInt throws if required and value missing", () => { | |||||||
|     ).toThrowError(); |     ).toThrowError(); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
|  | test("getInputAsBool returns false if input not set", () => { | ||||||
|  |     expect(actionUtils.getInputAsBool("undefined")).toBe(false); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | test("getInputAsBool returns value if input is valid", () => { | ||||||
|  |     testUtils.setInput("foo", "true"); | ||||||
|  |     expect(actionUtils.getInputAsBool("foo")).toBe(true); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | test("getInputAsBool returns false if input is invalid or NaN", () => { | ||||||
|  |     testUtils.setInput("foo", "bar"); | ||||||
|  |     expect(actionUtils.getInputAsBool("foo")).toBe(false); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | test("getInputAsBool throws if required and value missing", () => { | ||||||
|  |     expect(() => | ||||||
|  |         actionUtils.getInputAsBool("undefined2", { required: true }) | ||||||
|  |     ).toThrowError(); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
| test("isCacheFeatureAvailable for ac enabled", () => { | test("isCacheFeatureAvailable for ac enabled", () => { | ||||||
|     jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => true); |     jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => true); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -27,9 +27,17 @@ beforeAll(() => { | |||||||
|             return actualUtils.getInputAsArray(name, options); |             return actualUtils.getInputAsArray(name, options); | ||||||
|         } |         } | ||||||
|     ); |     ); | ||||||
|  | 
 | ||||||
|  |     jest.spyOn(actionUtils, "getInputAsBool").mockImplementation( | ||||||
|  |         (name, options) => { | ||||||
|  |             const actualUtils = jest.requireActual("../src/utils/actionUtils"); | ||||||
|  |             return actualUtils.getInputAsBool(name, options); | ||||||
|  |         } | ||||||
|  |     ); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| beforeEach(() => { | beforeEach(() => { | ||||||
|  |     jest.restoreAllMocks(); | ||||||
|     process.env[Events.Key] = Events.Push; |     process.env[Events.Key] = Events.Push; | ||||||
|     process.env[RefKey] = "refs/heads/feature-branch"; |     process.env[RefKey] = "refs/heads/feature-branch"; | ||||||
| 
 | 
 | ||||||
| @ -50,7 +58,8 @@ test("restore with no cache found", async () => { | |||||||
|     const key = "node-test"; |     const key = "node-test"; | ||||||
|     testUtils.setInputs({ |     testUtils.setInputs({ | ||||||
|         path: path, |         path: path, | ||||||
|         key |         key, | ||||||
|  |         enableCrossOsArchive: false | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const infoMock = jest.spyOn(core, "info"); |     const infoMock = jest.spyOn(core, "info"); | ||||||
| @ -65,7 +74,7 @@ test("restore with no cache found", async () => { | |||||||
|     await run(); |     await run(); | ||||||
| 
 | 
 | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); |     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []); |     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); | ||||||
| 
 | 
 | ||||||
|     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); |     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); | ||||||
|     expect(stateMock).toHaveBeenCalledTimes(1); |     expect(stateMock).toHaveBeenCalledTimes(1); | ||||||
| @ -84,7 +93,8 @@ test("restore with restore keys and no cache found", async () => { | |||||||
|     testUtils.setInputs({ |     testUtils.setInputs({ | ||||||
|         path: path, |         path: path, | ||||||
|         key, |         key, | ||||||
|         restoreKeys: [restoreKey] |         restoreKeys: [restoreKey], | ||||||
|  |         enableCrossOsArchive: false | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const infoMock = jest.spyOn(core, "info"); |     const infoMock = jest.spyOn(core, "info"); | ||||||
| @ -99,7 +109,13 @@ test("restore with restore keys and no cache found", async () => { | |||||||
|     await run(); |     await run(); | ||||||
| 
 | 
 | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); |     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]); |     expect(restoreCacheMock).toHaveBeenCalledWith( | ||||||
|  |         [path], | ||||||
|  |         key, | ||||||
|  |         [restoreKey], | ||||||
|  |         {}, | ||||||
|  |         false | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); |     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); | ||||||
|     expect(stateMock).toHaveBeenCalledTimes(1); |     expect(stateMock).toHaveBeenCalledTimes(1); | ||||||
| @ -116,7 +132,8 @@ test("restore with cache found for key", async () => { | |||||||
|     const key = "node-test"; |     const key = "node-test"; | ||||||
|     testUtils.setInputs({ |     testUtils.setInputs({ | ||||||
|         path: path, |         path: path, | ||||||
|         key |         key, | ||||||
|  |         enableCrossOsArchive: false | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const infoMock = jest.spyOn(core, "info"); |     const infoMock = jest.spyOn(core, "info"); | ||||||
| @ -132,7 +149,7 @@ test("restore with cache found for key", async () => { | |||||||
|     await run(); |     await run(); | ||||||
| 
 | 
 | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); |     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []); |     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); | ||||||
| 
 | 
 | ||||||
|     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); |     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); | ||||||
|     expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key); |     expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key); | ||||||
| @ -152,7 +169,8 @@ test("restore with cache found for restore key", async () => { | |||||||
|     testUtils.setInputs({ |     testUtils.setInputs({ | ||||||
|         path: path, |         path: path, | ||||||
|         key, |         key, | ||||||
|         restoreKeys: [restoreKey] |         restoreKeys: [restoreKey], | ||||||
|  |         enableCrossOsArchive: false | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const infoMock = jest.spyOn(core, "info"); |     const infoMock = jest.spyOn(core, "info"); | ||||||
| @ -168,7 +186,13 @@ test("restore with cache found for restore key", async () => { | |||||||
|     await run(); |     await run(); | ||||||
| 
 | 
 | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); |     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]); |     expect(restoreCacheMock).toHaveBeenCalledWith( | ||||||
|  |         [path], | ||||||
|  |         key, | ||||||
|  |         [restoreKey], | ||||||
|  |         {}, | ||||||
|  |         false | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); |     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); | ||||||
|     expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", restoreKey); |     expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", restoreKey); | ||||||
|  | |||||||
| @ -28,9 +28,17 @@ beforeAll(() => { | |||||||
|             return actualUtils.getInputAsArray(name, options); |             return actualUtils.getInputAsArray(name, options); | ||||||
|         } |         } | ||||||
|     ); |     ); | ||||||
|  | 
 | ||||||
|  |     jest.spyOn(actionUtils, "getInputAsBool").mockImplementation( | ||||||
|  |         (name, options) => { | ||||||
|  |             const actualUtils = jest.requireActual("../src/utils/actionUtils"); | ||||||
|  |             return actualUtils.getInputAsBool(name, options); | ||||||
|  |         } | ||||||
|  |     ); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| beforeEach(() => { | beforeEach(() => { | ||||||
|  |     jest.restoreAllMocks(); | ||||||
|     process.env[Events.Key] = Events.Push; |     process.env[Events.Key] = Events.Push; | ||||||
|     process.env[RefKey] = "refs/heads/feature-branch"; |     process.env[RefKey] = "refs/heads/feature-branch"; | ||||||
| 
 | 
 | ||||||
| @ -97,7 +105,8 @@ test("restore on GHES with AC available ", async () => { | |||||||
|     const key = "node-test"; |     const key = "node-test"; | ||||||
|     testUtils.setInputs({ |     testUtils.setInputs({ | ||||||
|         path: path, |         path: path, | ||||||
|         key |         key, | ||||||
|  |         enableCrossOsArchive: false | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const infoMock = jest.spyOn(core, "info"); |     const infoMock = jest.spyOn(core, "info"); | ||||||
| @ -113,7 +122,7 @@ test("restore on GHES with AC available ", async () => { | |||||||
|     await run(new StateProvider()); |     await run(new StateProvider()); | ||||||
| 
 | 
 | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); |     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []); |     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); | ||||||
| 
 | 
 | ||||||
|     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); |     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); | ||||||
|     expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); |     expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); | ||||||
| @ -152,13 +161,20 @@ test("restore with too many keys should fail", async () => { | |||||||
|     testUtils.setInputs({ |     testUtils.setInputs({ | ||||||
|         path: path, |         path: path, | ||||||
|         key, |         key, | ||||||
|         restoreKeys |         restoreKeys, | ||||||
|  |         enableCrossOsArchive: false | ||||||
|     }); |     }); | ||||||
|     const failedMock = jest.spyOn(core, "setFailed"); |     const failedMock = jest.spyOn(core, "setFailed"); | ||||||
|     const restoreCacheMock = jest.spyOn(cache, "restoreCache"); |     const restoreCacheMock = jest.spyOn(cache, "restoreCache"); | ||||||
|     await run(new StateProvider()); |     await run(new StateProvider()); | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); |     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, restoreKeys); |     expect(restoreCacheMock).toHaveBeenCalledWith( | ||||||
|  |         [path], | ||||||
|  |         key, | ||||||
|  |         restoreKeys, | ||||||
|  |         {}, | ||||||
|  |         false | ||||||
|  |     ); | ||||||
|     expect(failedMock).toHaveBeenCalledWith( |     expect(failedMock).toHaveBeenCalledWith( | ||||||
|         `Key Validation Error: Keys are limited to a maximum of 10.` |         `Key Validation Error: Keys are limited to a maximum of 10.` | ||||||
|     ); |     ); | ||||||
| @ -169,13 +185,14 @@ test("restore with large key should fail", async () => { | |||||||
|     const key = "foo".repeat(512); // Over the 512 character limit
 |     const key = "foo".repeat(512); // Over the 512 character limit
 | ||||||
|     testUtils.setInputs({ |     testUtils.setInputs({ | ||||||
|         path: path, |         path: path, | ||||||
|         key |         key, | ||||||
|  |         enableCrossOsArchive: false | ||||||
|     }); |     }); | ||||||
|     const failedMock = jest.spyOn(core, "setFailed"); |     const failedMock = jest.spyOn(core, "setFailed"); | ||||||
|     const restoreCacheMock = jest.spyOn(cache, "restoreCache"); |     const restoreCacheMock = jest.spyOn(cache, "restoreCache"); | ||||||
|     await run(new StateProvider()); |     await run(new StateProvider()); | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); |     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []); |     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); | ||||||
|     expect(failedMock).toHaveBeenCalledWith( |     expect(failedMock).toHaveBeenCalledWith( | ||||||
|         `Key Validation Error: ${key} cannot be larger than 512 characters.` |         `Key Validation Error: ${key} cannot be larger than 512 characters.` | ||||||
|     ); |     ); | ||||||
| @ -186,13 +203,14 @@ test("restore with invalid key should fail", async () => { | |||||||
|     const key = "comma,comma"; |     const key = "comma,comma"; | ||||||
|     testUtils.setInputs({ |     testUtils.setInputs({ | ||||||
|         path: path, |         path: path, | ||||||
|         key |         key, | ||||||
|  |         enableCrossOsArchive: false | ||||||
|     }); |     }); | ||||||
|     const failedMock = jest.spyOn(core, "setFailed"); |     const failedMock = jest.spyOn(core, "setFailed"); | ||||||
|     const restoreCacheMock = jest.spyOn(cache, "restoreCache"); |     const restoreCacheMock = jest.spyOn(cache, "restoreCache"); | ||||||
|     await run(new StateProvider()); |     await run(new StateProvider()); | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); |     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []); |     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); | ||||||
|     expect(failedMock).toHaveBeenCalledWith( |     expect(failedMock).toHaveBeenCalledWith( | ||||||
|         `Key Validation Error: ${key} cannot contain commas.` |         `Key Validation Error: ${key} cannot contain commas.` | ||||||
|     ); |     ); | ||||||
| @ -203,7 +221,8 @@ test("restore with no cache found", async () => { | |||||||
|     const key = "node-test"; |     const key = "node-test"; | ||||||
|     testUtils.setInputs({ |     testUtils.setInputs({ | ||||||
|         path: path, |         path: path, | ||||||
|         key |         key, | ||||||
|  |         enableCrossOsArchive: false | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const infoMock = jest.spyOn(core, "info"); |     const infoMock = jest.spyOn(core, "info"); | ||||||
| @ -218,7 +237,7 @@ test("restore with no cache found", async () => { | |||||||
|     await run(new StateProvider()); |     await run(new StateProvider()); | ||||||
| 
 | 
 | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); |     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []); |     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); | ||||||
| 
 | 
 | ||||||
|     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); |     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); | ||||||
|     expect(failedMock).toHaveBeenCalledTimes(0); |     expect(failedMock).toHaveBeenCalledTimes(0); | ||||||
| @ -235,7 +254,8 @@ test("restore with restore keys and no cache found", async () => { | |||||||
|     testUtils.setInputs({ |     testUtils.setInputs({ | ||||||
|         path: path, |         path: path, | ||||||
|         key, |         key, | ||||||
|         restoreKeys: [restoreKey] |         restoreKeys: [restoreKey], | ||||||
|  |         enableCrossOsArchive: false | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const infoMock = jest.spyOn(core, "info"); |     const infoMock = jest.spyOn(core, "info"); | ||||||
| @ -250,7 +270,13 @@ test("restore with restore keys and no cache found", async () => { | |||||||
|     await run(new StateProvider()); |     await run(new StateProvider()); | ||||||
| 
 | 
 | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); |     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]); |     expect(restoreCacheMock).toHaveBeenCalledWith( | ||||||
|  |         [path], | ||||||
|  |         key, | ||||||
|  |         [restoreKey], | ||||||
|  |         {}, | ||||||
|  |         false | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); |     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); | ||||||
|     expect(failedMock).toHaveBeenCalledTimes(0); |     expect(failedMock).toHaveBeenCalledTimes(0); | ||||||
| @ -265,7 +291,8 @@ test("restore with cache found for key", async () => { | |||||||
|     const key = "node-test"; |     const key = "node-test"; | ||||||
|     testUtils.setInputs({ |     testUtils.setInputs({ | ||||||
|         path: path, |         path: path, | ||||||
|         key |         key, | ||||||
|  |         enableCrossOsArchive: false | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const infoMock = jest.spyOn(core, "info"); |     const infoMock = jest.spyOn(core, "info"); | ||||||
| @ -281,7 +308,7 @@ test("restore with cache found for key", async () => { | |||||||
|     await run(new StateProvider()); |     await run(new StateProvider()); | ||||||
| 
 | 
 | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); |     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []); |     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); | ||||||
| 
 | 
 | ||||||
|     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); |     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); | ||||||
|     expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); |     expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); | ||||||
| @ -298,7 +325,8 @@ test("restore with cache found for restore key", async () => { | |||||||
|     testUtils.setInputs({ |     testUtils.setInputs({ | ||||||
|         path: path, |         path: path, | ||||||
|         key, |         key, | ||||||
|         restoreKeys: [restoreKey] |         restoreKeys: [restoreKey], | ||||||
|  |         enableCrossOsArchive: false | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const infoMock = jest.spyOn(core, "info"); |     const infoMock = jest.spyOn(core, "info"); | ||||||
| @ -314,7 +342,13 @@ test("restore with cache found for restore key", async () => { | |||||||
|     await run(new StateProvider()); |     await run(new StateProvider()); | ||||||
| 
 | 
 | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); |     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]); |     expect(restoreCacheMock).toHaveBeenCalledWith( | ||||||
|  |         [path], | ||||||
|  |         key, | ||||||
|  |         [restoreKey], | ||||||
|  |         {}, | ||||||
|  |         false | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); |     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); | ||||||
|     expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); |     expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); | ||||||
|  | |||||||
| @ -27,9 +27,18 @@ beforeAll(() => { | |||||||
|             return actualUtils.getInputAsArray(name, options); |             return actualUtils.getInputAsArray(name, options); | ||||||
|         } |         } | ||||||
|     ); |     ); | ||||||
|  | 
 | ||||||
|  |     jest.spyOn(actionUtils, "getInputAsBool").mockImplementation( | ||||||
|  |         (name, options) => { | ||||||
|  |             return jest | ||||||
|  |                 .requireActual("../src/utils/actionUtils") | ||||||
|  |                 .getInputAsBool(name, options); | ||||||
|  |         } | ||||||
|  |     ); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| beforeEach(() => { | beforeEach(() => { | ||||||
|  |     jest.restoreAllMocks(); | ||||||
|     process.env[Events.Key] = Events.Push; |     process.env[Events.Key] = Events.Push; | ||||||
|     process.env[RefKey] = "refs/heads/feature-branch"; |     process.env[RefKey] = "refs/heads/feature-branch"; | ||||||
| 
 | 
 | ||||||
| @ -50,7 +59,8 @@ test("restore with no cache found", async () => { | |||||||
|     const key = "node-test"; |     const key = "node-test"; | ||||||
|     testUtils.setInputs({ |     testUtils.setInputs({ | ||||||
|         path: path, |         path: path, | ||||||
|         key |         key, | ||||||
|  |         enableCrossOsArchive: false | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const infoMock = jest.spyOn(core, "info"); |     const infoMock = jest.spyOn(core, "info"); | ||||||
| @ -65,7 +75,7 @@ test("restore with no cache found", async () => { | |||||||
|     await run(); |     await run(); | ||||||
| 
 | 
 | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); |     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []); |     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); | ||||||
| 
 | 
 | ||||||
|     expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key); |     expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key); | ||||||
|     expect(outputMock).toHaveBeenCalledTimes(1); |     expect(outputMock).toHaveBeenCalledTimes(1); | ||||||
| @ -83,7 +93,8 @@ test("restore with restore keys and no cache found", async () => { | |||||||
|     testUtils.setInputs({ |     testUtils.setInputs({ | ||||||
|         path: path, |         path: path, | ||||||
|         key, |         key, | ||||||
|         restoreKeys: [restoreKey] |         restoreKeys: [restoreKey], | ||||||
|  |         enableCrossOsArchive: false | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const infoMock = jest.spyOn(core, "info"); |     const infoMock = jest.spyOn(core, "info"); | ||||||
| @ -98,7 +109,13 @@ test("restore with restore keys and no cache found", async () => { | |||||||
|     await run(); |     await run(); | ||||||
| 
 | 
 | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); |     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]); |     expect(restoreCacheMock).toHaveBeenCalledWith( | ||||||
|  |         [path], | ||||||
|  |         key, | ||||||
|  |         [restoreKey], | ||||||
|  |         {}, | ||||||
|  |         false | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key); |     expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key); | ||||||
|     expect(failedMock).toHaveBeenCalledTimes(0); |     expect(failedMock).toHaveBeenCalledTimes(0); | ||||||
| @ -113,7 +130,8 @@ test("restore with cache found for key", async () => { | |||||||
|     const key = "node-test"; |     const key = "node-test"; | ||||||
|     testUtils.setInputs({ |     testUtils.setInputs({ | ||||||
|         path: path, |         path: path, | ||||||
|         key |         key, | ||||||
|  |         enableCrossOsArchive: false | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const infoMock = jest.spyOn(core, "info"); |     const infoMock = jest.spyOn(core, "info"); | ||||||
| @ -128,7 +146,7 @@ test("restore with cache found for key", async () => { | |||||||
|     await run(); |     await run(); | ||||||
| 
 | 
 | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); |     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []); |     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false); | ||||||
| 
 | 
 | ||||||
|     expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key); |     expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key); | ||||||
|     expect(outputMock).toHaveBeenCalledWith("cache-hit", "true"); |     expect(outputMock).toHaveBeenCalledWith("cache-hit", "true"); | ||||||
| @ -147,7 +165,8 @@ test("restore with cache found for restore key", async () => { | |||||||
|     testUtils.setInputs({ |     testUtils.setInputs({ | ||||||
|         path: path, |         path: path, | ||||||
|         key, |         key, | ||||||
|         restoreKeys: [restoreKey] |         restoreKeys: [restoreKey], | ||||||
|  |         enableCrossOsArchive: false | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const infoMock = jest.spyOn(core, "info"); |     const infoMock = jest.spyOn(core, "info"); | ||||||
| @ -162,7 +181,13 @@ test("restore with cache found for restore key", async () => { | |||||||
|     await run(); |     await run(); | ||||||
| 
 | 
 | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); |     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]); |     expect(restoreCacheMock).toHaveBeenCalledWith( | ||||||
|  |         [path], | ||||||
|  |         key, | ||||||
|  |         [restoreKey], | ||||||
|  |         {}, | ||||||
|  |         false | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key); |     expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key); | ||||||
|     expect(outputMock).toHaveBeenCalledWith("cache-hit", "false"); |     expect(outputMock).toHaveBeenCalledWith("cache-hit", "false"); | ||||||
|  | |||||||
| @ -35,6 +35,14 @@ beforeAll(() => { | |||||||
|         } |         } | ||||||
|     ); |     ); | ||||||
| 
 | 
 | ||||||
|  |     jest.spyOn(actionUtils, "getInputAsBool").mockImplementation( | ||||||
|  |         (name, options) => { | ||||||
|  |             return jest | ||||||
|  |                 .requireActual("../src/utils/actionUtils") | ||||||
|  |                 .getInputAsBool(name, options); | ||||||
|  |         } | ||||||
|  |     ); | ||||||
|  | 
 | ||||||
|     jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation( |     jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation( | ||||||
|         (key, cacheResult) => { |         (key, cacheResult) => { | ||||||
|             return jest |             return jest | ||||||
| @ -95,9 +103,14 @@ test("save with valid inputs uploads a cache", async () => { | |||||||
|     await run(); |     await run(); | ||||||
| 
 | 
 | ||||||
|     expect(saveCacheMock).toHaveBeenCalledTimes(1); |     expect(saveCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(saveCacheMock).toHaveBeenCalledWith([inputPath], primaryKey, { |     expect(saveCacheMock).toHaveBeenCalledWith( | ||||||
|  |         [inputPath], | ||||||
|  |         primaryKey, | ||||||
|  |         { | ||||||
|             uploadChunkSize: 4000000 |             uploadChunkSize: 4000000 | ||||||
|     }); |         }, | ||||||
|  |         false | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     expect(failedMock).toHaveBeenCalledTimes(0); |     expect(failedMock).toHaveBeenCalledTimes(0); | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -32,6 +32,14 @@ beforeAll(() => { | |||||||
|         } |         } | ||||||
|     ); |     ); | ||||||
| 
 | 
 | ||||||
|  |     jest.spyOn(actionUtils, "getInputAsBool").mockImplementation( | ||||||
|  |         (name, options) => { | ||||||
|  |             return jest | ||||||
|  |                 .requireActual("../src/utils/actionUtils") | ||||||
|  |                 .getInputAsBool(name, options); | ||||||
|  |         } | ||||||
|  |     ); | ||||||
|  | 
 | ||||||
|     jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation( |     jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation( | ||||||
|         (key, cacheResult) => { |         (key, cacheResult) => { | ||||||
|             return jest |             return jest | ||||||
| @ -47,6 +55,7 @@ beforeAll(() => { | |||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| beforeEach(() => { | beforeEach(() => { | ||||||
|  |     jest.restoreAllMocks(); | ||||||
|     process.env[Events.Key] = Events.Push; |     process.env[Events.Key] = Events.Push; | ||||||
|     process.env[RefKey] = "refs/heads/feature-branch"; |     process.env[RefKey] = "refs/heads/feature-branch"; | ||||||
| 
 | 
 | ||||||
| @ -157,7 +166,7 @@ test("save on GHES with AC available", async () => { | |||||||
|     expect(saveCacheMock).toHaveBeenCalledTimes(1); |     expect(saveCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(saveCacheMock).toHaveBeenCalledWith([inputPath], primaryKey, { |     expect(saveCacheMock).toHaveBeenCalledWith([inputPath], primaryKey, { | ||||||
|         uploadChunkSize: 4000000 |         uploadChunkSize: 4000000 | ||||||
|     }); |     }, false); | ||||||
| 
 | 
 | ||||||
|     expect(failedMock).toHaveBeenCalledTimes(0); |     expect(failedMock).toHaveBeenCalledTimes(0); | ||||||
| }); | }); | ||||||
| @ -251,7 +260,8 @@ test("save with large cache outputs warning", async () => { | |||||||
|     expect(saveCacheMock).toHaveBeenCalledWith( |     expect(saveCacheMock).toHaveBeenCalledWith( | ||||||
|         [inputPath], |         [inputPath], | ||||||
|         primaryKey, |         primaryKey, | ||||||
|         expect.anything() |         expect.anything(), | ||||||
|  |         false | ||||||
|     ); |     ); | ||||||
| 
 | 
 | ||||||
|     expect(logWarningMock).toHaveBeenCalledTimes(1); |     expect(logWarningMock).toHaveBeenCalledTimes(1); | ||||||
| @ -297,7 +307,8 @@ test("save with reserve cache failure outputs warning", async () => { | |||||||
|     expect(saveCacheMock).toHaveBeenCalledWith( |     expect(saveCacheMock).toHaveBeenCalledWith( | ||||||
|         [inputPath], |         [inputPath], | ||||||
|         primaryKey, |         primaryKey, | ||||||
|         expect.anything() |         expect.anything(), | ||||||
|  |         false | ||||||
|     ); |     ); | ||||||
| 
 | 
 | ||||||
|     expect(logWarningMock).toHaveBeenCalledWith( |     expect(logWarningMock).toHaveBeenCalledWith( | ||||||
| @ -339,7 +350,8 @@ test("save with server error outputs warning", async () => { | |||||||
|     expect(saveCacheMock).toHaveBeenCalledWith( |     expect(saveCacheMock).toHaveBeenCalledWith( | ||||||
|         [inputPath], |         [inputPath], | ||||||
|         primaryKey, |         primaryKey, | ||||||
|         expect.anything() |         expect.anything(), | ||||||
|  |         false | ||||||
|     ); |     ); | ||||||
| 
 | 
 | ||||||
|     expect(logWarningMock).toHaveBeenCalledTimes(1); |     expect(logWarningMock).toHaveBeenCalledTimes(1); | ||||||
| @ -378,9 +390,14 @@ test("save with valid inputs uploads a cache", async () => { | |||||||
|     await run(new StateProvider()); |     await run(new StateProvider()); | ||||||
| 
 | 
 | ||||||
|     expect(saveCacheMock).toHaveBeenCalledTimes(1); |     expect(saveCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(saveCacheMock).toHaveBeenCalledWith([inputPath], primaryKey, { |     expect(saveCacheMock).toHaveBeenCalledWith( | ||||||
|  |         [inputPath], | ||||||
|  |         primaryKey, | ||||||
|  |         { | ||||||
|             uploadChunkSize: 4000000 |             uploadChunkSize: 4000000 | ||||||
|     }); |         }, | ||||||
|  |         false | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     expect(failedMock).toHaveBeenCalledTimes(0); |     expect(failedMock).toHaveBeenCalledTimes(0); | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -35,6 +35,14 @@ beforeAll(() => { | |||||||
|         } |         } | ||||||
|     ); |     ); | ||||||
| 
 | 
 | ||||||
|  |     jest.spyOn(actionUtils, "getInputAsBool").mockImplementation( | ||||||
|  |         (name, options) => { | ||||||
|  |             return jest | ||||||
|  |                 .requireActual("../src/utils/actionUtils") | ||||||
|  |                 .getInputAsBool(name, options); | ||||||
|  |         } | ||||||
|  |     ); | ||||||
|  | 
 | ||||||
|     jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation( |     jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation( | ||||||
|         (key, cacheResult) => { |         (key, cacheResult) => { | ||||||
|             return jest |             return jest | ||||||
| @ -85,9 +93,14 @@ test("save with valid inputs uploads a cache", async () => { | |||||||
|     await run(); |     await run(); | ||||||
| 
 | 
 | ||||||
|     expect(saveCacheMock).toHaveBeenCalledTimes(1); |     expect(saveCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(saveCacheMock).toHaveBeenCalledWith([inputPath], primaryKey, { |     expect(saveCacheMock).toHaveBeenCalledWith( | ||||||
|  |         [inputPath], | ||||||
|  |         primaryKey, | ||||||
|  |         { | ||||||
|             uploadChunkSize: 4000000 |             uploadChunkSize: 4000000 | ||||||
|     }); |         }, | ||||||
|  |         false | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     expect(failedMock).toHaveBeenCalledTimes(0); |     expect(failedMock).toHaveBeenCalledTimes(0); | ||||||
| }); | }); | ||||||
| @ -112,9 +125,14 @@ test("save failing logs the warning message", async () => { | |||||||
|     await run(); |     await run(); | ||||||
| 
 | 
 | ||||||
|     expect(saveCacheMock).toHaveBeenCalledTimes(1); |     expect(saveCacheMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(saveCacheMock).toHaveBeenCalledWith([inputPath], primaryKey, { |     expect(saveCacheMock).toHaveBeenCalledWith( | ||||||
|  |         [inputPath], | ||||||
|  |         primaryKey, | ||||||
|  |         { | ||||||
|             uploadChunkSize: 4000000 |             uploadChunkSize: 4000000 | ||||||
|     }); |         }, | ||||||
|  |         false | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     expect(warningMock).toHaveBeenCalledTimes(1); |     expect(warningMock).toHaveBeenCalledTimes(1); | ||||||
|     expect(warningMock).toHaveBeenCalledWith("Cache save failed."); |     expect(warningMock).toHaveBeenCalledWith("Cache save failed."); | ||||||
|  | |||||||
| @ -15,7 +15,7 @@ inputs: | |||||||
|     description: 'The chunk size used to split up large files during upload, in bytes' |     description: 'The chunk size used to split up large files during upload, in bytes' | ||||||
|     required: false |     required: false | ||||||
|   enableCrossOsArchive: |   enableCrossOsArchive: | ||||||
|     description: 'An optional boolean enabled to save and restore cache on windows which could be restored and saved on any platform' |     description: 'An optional boolean when enabled, allows windows runners to save/restore caches that can be restored/saved respectively on other platforms' | ||||||
|     default: 'false' |     default: 'false' | ||||||
|     required: false |     required: false | ||||||
| outputs: | outputs: | ||||||
|  | |||||||
							
								
								
									
										3
									
								
								dist/restore-only/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								dist/restore-only/index.js
									
									
									
									
										vendored
									
									
								
							| @ -10118,7 +10118,8 @@ function getInputAsInt(name, options) { | |||||||
| } | } | ||||||
| exports.getInputAsInt = getInputAsInt; | exports.getInputAsInt = getInputAsInt; | ||||||
| function getInputAsBool(name, options) { | function getInputAsBool(name, options) { | ||||||
|     return core.getBooleanInput(name, options); |     const result = core.getInput(name, options); | ||||||
|  |     return result.toLowerCase() === "true"; | ||||||
| } | } | ||||||
| exports.getInputAsBool = getInputAsBool; | exports.getInputAsBool = getInputAsBool; | ||||||
| function isCacheFeatureAvailable() { | function isCacheFeatureAvailable() { | ||||||
|  | |||||||
							
								
								
									
										3
									
								
								dist/restore/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								dist/restore/index.js
									
									
									
									
										vendored
									
									
								
							| @ -38646,7 +38646,8 @@ function getInputAsInt(name, options) { | |||||||
| } | } | ||||||
| exports.getInputAsInt = getInputAsInt; | exports.getInputAsInt = getInputAsInt; | ||||||
| function getInputAsBool(name, options) { | function getInputAsBool(name, options) { | ||||||
|     return core.getBooleanInput(name, options); |     const result = core.getInput(name, options); | ||||||
|  |     return result.toLowerCase() === "true"; | ||||||
| } | } | ||||||
| exports.getInputAsBool = getInputAsBool; | exports.getInputAsBool = getInputAsBool; | ||||||
| function isCacheFeatureAvailable() { | function isCacheFeatureAvailable() { | ||||||
|  | |||||||
							
								
								
									
										3
									
								
								dist/save-only/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								dist/save-only/index.js
									
									
									
									
										vendored
									
									
								
							| @ -38697,7 +38697,8 @@ function getInputAsInt(name, options) { | |||||||
| } | } | ||||||
| exports.getInputAsInt = getInputAsInt; | exports.getInputAsInt = getInputAsInt; | ||||||
| function getInputAsBool(name, options) { | function getInputAsBool(name, options) { | ||||||
|     return core.getBooleanInput(name, options); |     const result = core.getInput(name, options); | ||||||
|  |     return result.toLowerCase() === "true"; | ||||||
| } | } | ||||||
| exports.getInputAsBool = getInputAsBool; | exports.getInputAsBool = getInputAsBool; | ||||||
| function isCacheFeatureAvailable() { | function isCacheFeatureAvailable() { | ||||||
|  | |||||||
							
								
								
									
										3
									
								
								dist/save/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								dist/save/index.js
									
									
									
									
										vendored
									
									
								
							| @ -38641,7 +38641,8 @@ function getInputAsInt(name, options) { | |||||||
| } | } | ||||||
| exports.getInputAsInt = getInputAsInt; | exports.getInputAsInt = getInputAsInt; | ||||||
| function getInputAsBool(name, options) { | function getInputAsBool(name, options) { | ||||||
|     return core.getBooleanInput(name, options); |     const result = core.getInput(name, options); | ||||||
|  |     return result.toLowerCase() === "true"; | ||||||
| } | } | ||||||
| exports.getInputAsBool = getInputAsBool; | exports.getInputAsBool = getInputAsBool; | ||||||
| function isCacheFeatureAvailable() { | function isCacheFeatureAvailable() { | ||||||
|  | |||||||
| @ -12,7 +12,7 @@ inputs: | |||||||
|     description: 'An ordered list of keys to use for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.' |     description: 'An ordered list of keys to use for restoring stale cache if no cache hit occurred for key. Note `cache-hit` returns false in this case.' | ||||||
|     required: false |     required: false | ||||||
|   enableCrossOsArchive: |   enableCrossOsArchive: | ||||||
|     description: 'An optional boolean enabled to restore cache on windows which could be saved on any platform' |     description: 'An optional boolean to enable restoring a cache on Windows which was created on another platform' | ||||||
|     default: 'false' |     default: 'false' | ||||||
|     required: false |     required: false | ||||||
| outputs: | outputs: | ||||||
|  | |||||||
| @ -12,7 +12,7 @@ inputs: | |||||||
|     description: 'The chunk size used to split up large files during upload, in bytes' |     description: 'The chunk size used to split up large files during upload, in bytes' | ||||||
|     required: false |     required: false | ||||||
|   enableCrossOsArchive: |   enableCrossOsArchive: | ||||||
|     description: 'An optional boolean enabled to save cache on windows which could be restored on any platform' |     description: 'An optional boolean to enable saving a cache on Windows which may be restored later on another platform' | ||||||
|     default: 'false' |     default: 'false' | ||||||
|     required: false |     required: false | ||||||
| runs: | runs: | ||||||
|  | |||||||
| @ -56,7 +56,8 @@ export function getInputAsBool( | |||||||
|     name: string, |     name: string, | ||||||
|     options?: core.InputOptions |     options?: core.InputOptions | ||||||
| ): boolean { | ): boolean { | ||||||
|     return core.getBooleanInput(name, options); |     const result = core.getInput(name, options); | ||||||
|  |     return result.toLowerCase() === "true"; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export function isCacheFeatureAvailable(): boolean { | export function isCacheFeatureAvailable(): boolean { | ||||||
|  | |||||||
| @ -13,6 +13,7 @@ interface CacheInput { | |||||||
|     path: string; |     path: string; | ||||||
|     key: string; |     key: string; | ||||||
|     restoreKeys?: string[]; |     restoreKeys?: string[]; | ||||||
|  |     enableCrossOsArchive?: boolean; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export function setInputs(input: CacheInput): void { | export function setInputs(input: CacheInput): void { | ||||||
| @ -20,6 +21,11 @@ export function setInputs(input: CacheInput): void { | |||||||
|     setInput(Inputs.Key, input.key); |     setInput(Inputs.Key, input.key); | ||||||
|     input.restoreKeys && |     input.restoreKeys && | ||||||
|         setInput(Inputs.RestoreKeys, input.restoreKeys.join("\n")); |         setInput(Inputs.RestoreKeys, input.restoreKeys.join("\n")); | ||||||
|  |     input.enableCrossOsArchive !== undefined && | ||||||
|  |         setInput( | ||||||
|  |             Inputs.EnableCrossOsArchive, | ||||||
|  |             input.enableCrossOsArchive.toString() | ||||||
|  |         ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export function clearInputs(): void { | export function clearInputs(): void { | ||||||
| @ -27,4 +33,5 @@ export function clearInputs(): void { | |||||||
|     delete process.env[getInputName(Inputs.Key)]; |     delete process.env[getInputName(Inputs.Key)]; | ||||||
|     delete process.env[getInputName(Inputs.RestoreKeys)]; |     delete process.env[getInputName(Inputs.RestoreKeys)]; | ||||||
|     delete process.env[getInputName(Inputs.UploadChunkSize)]; |     delete process.env[getInputName(Inputs.UploadChunkSize)]; | ||||||
|  |     delete process.env[getInputName(Inputs.EnableCrossOsArchive)]; | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Sampark Sharma
						Sampark Sharma