12
0
Fork 0
mirror of https://github.com/actions/cache.git synced 2026-06-29 04:00:43 +00:00
This commit is contained in:
Nathan Harris 2026-06-23 10:12:33 -05:00 committed by GitHub
commit 1524323399
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 119 additions and 2 deletions

View file

@ -253,6 +253,84 @@ test("save with server error outputs warning", async () => {
expect(core.setFailed).toHaveBeenCalledTimes(0);
});
test("save with fail-on-error and save error calls setFailed", async () => {
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
const failedMock = jest.spyOn(core, "setFailed");
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
const savedCacheKey = "Linux-node-";
jest.spyOn(core, "getState")
.mockImplementationOnce(() => savedCacheKey)
.mockImplementationOnce(() => primaryKey);
const inputPath = "node_modules";
testUtils.setInput(Inputs.Path, inputPath);
testUtils.setInput(Inputs.FailOnError, "true");
jest.spyOn(cache, "saveCache").mockImplementationOnce(() => {
throw new Error("HTTP Error Occurred");
});
await saveImpl(new StateProvider());
expect(failedMock).toHaveBeenCalledWith("HTTP Error Occurred");
expect(failedMock).toHaveBeenCalledTimes(1);
expect(logWarningMock).toHaveBeenCalledTimes(0);
});
test("save with fail-on-save-error (global action input) and save error calls setFailed", async () => {
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
const failedMock = jest.spyOn(core, "setFailed");
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
const savedCacheKey = "Linux-node-";
jest.spyOn(core, "getState")
.mockImplementationOnce(() => savedCacheKey)
.mockImplementationOnce(() => primaryKey);
const inputPath = "node_modules";
testUtils.setInput(Inputs.Path, inputPath);
testUtils.setInput(Inputs.FailOnSaveError, "true");
jest.spyOn(cache, "saveCache").mockImplementationOnce(() => {
throw new Error("HTTP Error Occurred");
});
await saveImpl(new StateProvider());
expect(failedMock).toHaveBeenCalledWith("HTTP Error Occurred");
expect(failedMock).toHaveBeenCalledTimes(1);
expect(logWarningMock).toHaveBeenCalledTimes(0);
});
test("save with fail-on-error false and save error logs warning", async () => {
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
const failedMock = jest.spyOn(core, "setFailed");
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
const savedCacheKey = "Linux-node-";
jest.spyOn(core, "getState")
.mockImplementationOnce(() => savedCacheKey)
.mockImplementationOnce(() => primaryKey);
const inputPath = "node_modules";
testUtils.setInput(Inputs.Path, inputPath);
testUtils.setInput(Inputs.FailOnError, "false");
jest.spyOn(cache, "saveCache").mockImplementationOnce(() => {
throw new Error("HTTP Error Occurred");
});
await saveImpl(new StateProvider());
expect(logWarningMock).toHaveBeenCalledWith("HTTP Error Occurred");
expect(logWarningMock).toHaveBeenCalledTimes(1);
expect(failedMock).toHaveBeenCalledTimes(0);
});
test("save with valid inputs uploads a cache", async () => {
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
const savedCacheKey = "Linux-node-";