Only fail if no cache entry is found

This commit is contained in:
Marc Mueller 2023-01-09 16:03:44 +01:00
parent d05f7e6483
commit 155f8e7a3c
7 changed files with 13 additions and 21 deletions

View file

@ -206,7 +206,7 @@ test("restore with cache found for restore key", async () => {
expect(failedMock).toHaveBeenCalledTimes(0);
});
test("Fail restore when fail on cache miss is enabled and primary key not found", async () => {
test("Fail restore when fail on cache miss is enabled and primary + restore keys not found", async () => {
const path = "node_modules";
const key = "node-test";
const restoreKey = "node-";
@ -246,7 +246,7 @@ test("Fail restore when fail on cache miss is enabled and primary key not found"
expect(failedMock).toHaveBeenCalledTimes(1);
});
test("Fail restore when fail on cache miss is enabled and primary key doesn't match restored key", async () => {
test("restore when fail on cache miss is enabled and primary key doesn't match restored key", async () => {
const path = "node_modules";
const key = "node-test";
const restoreKey = "node-";
@ -257,6 +257,7 @@ test("Fail restore when fail on cache miss is enabled and primary key doesn't ma
failOnCacheMiss: 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");
@ -278,11 +279,14 @@ test("Fail restore when fail on cache miss is enabled and primary key doesn't ma
);
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
expect(stateMock).toHaveBeenCalledTimes(2);
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false");
expect(failedMock).toHaveBeenCalledWith(
`Restored cache key doesn't match the given input key. Exiting as fail-on-cache-miss is set. Input key: ${key}`
expect(infoMock).toHaveBeenCalledWith(
`Cache restored from key: ${restoreKey}`
);
expect(failedMock).toHaveBeenCalledTimes(1);
expect(failedMock).toHaveBeenCalledTimes(0);
});