Skip to content

Commit

Permalink
formatting and error
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubham Tiwari authored and GitHub committed Jun 24, 2022
1 parent c75dca6 commit 7c59aeb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .licenses/npm/@actions/cache.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 0 additions & 34 deletions __tests__/restore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,40 +227,6 @@ test("restore with no cache found", async () => {
);
});

test("restore with server error should fail", async () => {
const path = "node_modules";
const key = "node-test";
testUtils.setInputs({
path: path,
key
});

const logWarningMock = jest.spyOn(actionUtils, "logWarning");
const failedMock = jest.spyOn(core, "setFailed");
const stateMock = jest.spyOn(core, "saveState");
const restoreCacheMock = jest
.spyOn(cache, "restoreCache")
.mockImplementationOnce(() => {
throw new Error("HTTP Error Occurred");
});
const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");

await run();

expect(restoreCacheMock).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);

expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);

expect(logWarningMock).toHaveBeenCalledTimes(1);
expect(logWarningMock).toHaveBeenCalledWith("HTTP Error Occurred");

expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
expect(setCacheHitOutputMock).toHaveBeenCalledWith(false);

expect(failedMock).toHaveBeenCalledTimes(0);
});

test("restore with restore keys and no cache found", async () => {
const path = "node_modules";
const key = "node-test";
Expand Down
4 changes: 2 additions & 2 deletions src/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ async function run(): Promise<void> {
primaryKey,
restoreKeys
);

if (!cacheKey) {
core.info(
`Cache not found for input keys: ${[
primaryKey,
...restoreKeys
].join(", ")}`
].join(", ")}`
);

return;
Expand Down
10 changes: 5 additions & 5 deletions src/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ async function run(): Promise<void> {
required: true
});

const cacheId = await cache.saveCache(cachePaths, primaryKey, {
uploadChunkSize: utils.getInputAsInt(Inputs.UploadChunkSize)
});
if (cacheId == -1 ) {
const cacheId = await cache.saveCache(cachePaths, primaryKey, {
uploadChunkSize: utils.getInputAsInt(Inputs.UploadChunkSize)
});
if (cacheId == -1) {
return;
}

core.info(`Cache saved with key: ${primaryKey}`);
} catch (error: unknown) {
utils.logWarning((error as Error).message);
Expand Down

0 comments on commit 7c59aeb

Please sign in to comment.