mirror of
				https://gitea.com/actions/cache.git
				synced 2025-10-31 07:47:07 +00:00 
			
		
		
		
	initial changes
This commit is contained in:
		| @@ -34,6 +34,7 @@ beforeEach(() => { | ||||
|     process.env[RefKey] = "refs/heads/feature-branch"; | ||||
|  | ||||
|     jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false); | ||||
|     jest.spyOn(cache, "isAvailable").mockImplementation(() => true); | ||||
| }); | ||||
|  | ||||
| afterEach(() => { | ||||
| @@ -55,8 +56,9 @@ test("restore with invalid event outputs warning", async () => { | ||||
|     expect(failedMock).toHaveBeenCalledTimes(0); | ||||
| }); | ||||
|  | ||||
| test("restore on GHES should no-op", async () => { | ||||
|     jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true); | ||||
| test("restore without AC available should no-op", async () => { | ||||
|     jest.spyOn(actionUtils, "isGhes").mockImplementation(() => false); | ||||
|     jest.spyOn(cache, "isAvailable").mockImplementation(() => false); | ||||
|  | ||||
|     const logWarningMock = jest.spyOn(actionUtils, "logWarning"); | ||||
|     const restoreCacheMock = jest.spyOn(cache, "restoreCache"); | ||||
| @@ -68,10 +70,60 @@ test("restore on GHES should no-op", async () => { | ||||
|     expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); | ||||
|     expect(setCacheHitOutputMock).toHaveBeenCalledWith(false); | ||||
|     expect(logWarningMock).toHaveBeenCalledWith( | ||||
|         "Cache action is not supported on GHES. See https://github.com/actions/cache/issues/505 for more details" | ||||
|         "Something is going wrong with ArtifactCache service which supports cache actions. Please check https://www.githubstatus.com/ for any ongoing issue in actions." | ||||
|     ); | ||||
| }); | ||||
|  | ||||
| test("restore on GHES without AC available should no-op", async () => { | ||||
|     jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true); | ||||
|     jest.spyOn(cache, "isAvailable").mockImplementation(() => false); | ||||
|  | ||||
|     const logWarningMock = jest.spyOn(actionUtils, "logWarning"); | ||||
|     const restoreCacheMock = jest.spyOn(cache, "restoreCache"); | ||||
|     const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput"); | ||||
|  | ||||
|     await run(); | ||||
|  | ||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(0); | ||||
|     expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); | ||||
|     expect(setCacheHitOutputMock).toHaveBeenCalledWith(false); | ||||
|     expect(logWarningMock).toHaveBeenCalledWith( | ||||
|         "Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if ArtifactCache service is enabled or not." | ||||
|     ); | ||||
| }); | ||||
|  | ||||
| test("restore on GHES with AC available ", async () => { | ||||
|     jest.spyOn(actionUtils, "isGhes").mockImplementation(() => true); | ||||
|     const path = "node_modules"; | ||||
|     const key = "node-test"; | ||||
|     testUtils.setInputs({ | ||||
|         path: path, | ||||
|         key | ||||
|     }); | ||||
|  | ||||
|     const infoMock = jest.spyOn(core, "info"); | ||||
|     const failedMock = jest.spyOn(core, "setFailed"); | ||||
|     const stateMock = jest.spyOn(core, "saveState"); | ||||
|     const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput"); | ||||
|     const restoreCacheMock = jest | ||||
|         .spyOn(cache, "restoreCache") | ||||
|         .mockImplementationOnce(() => { | ||||
|             return Promise.resolve(key); | ||||
|         }); | ||||
|  | ||||
|     await run(); | ||||
|  | ||||
|     expect(restoreCacheMock).toHaveBeenCalledTimes(1); | ||||
|     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []); | ||||
|  | ||||
|     expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key); | ||||
|     expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1); | ||||
|     expect(setCacheHitOutputMock).toHaveBeenCalledWith(true); | ||||
|  | ||||
|     expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`); | ||||
|     expect(failedMock).toHaveBeenCalledTimes(0); | ||||
| }); | ||||
|  | ||||
| test("restore with no path should fail", async () => { | ||||
|     const failedMock = jest.spyOn(core, "setFailed"); | ||||
|     const restoreCacheMock = jest.spyOn(cache, "restoreCache"); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Shubham Tiwari
					Shubham Tiwari