From b417e128396d9373100d934ae04076b0121c750b Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 9 Mar 2023 13:15:14 +0100 Subject: [PATCH] Move test case --- __tests__/restore.test.ts | 45 ----------------------------------- __tests__/restoreImpl.test.ts | 45 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index c8c4029..c51c293 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -356,48 +356,3 @@ test("restore with fail on cache miss disabled and no cache found", 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(); - - 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); -}); diff --git a/__tests__/restoreImpl.test.ts b/__tests__/restoreImpl.test.ts index 315fc7a..d6f13ba 100644 --- a/__tests__/restoreImpl.test.ts +++ b/__tests__/restoreImpl.test.ts @@ -404,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); +});