From 7f5799b6ac36a8b4f054a00d3c5bd356af665eb9 Mon Sep 17 00:00:00 2001
From: bruce <bchen1029@gmail.com>
Date: Tue, 26 Jul 2022 15:18:53 +0800
Subject: [PATCH] fix: fix cache-hit value when cache not found

---
 __tests__/restore.test.ts | 8 ++++++++
 src/restore.ts            | 1 +
 2 files changed, 9 insertions(+)

diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts
index e9a505b..951c94c 100644
--- a/__tests__/restore.test.ts
+++ b/__tests__/restore.test.ts
@@ -205,6 +205,7 @@ test("restore with no cache found", async () => {
         key
     });
 
+    const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
     const infoMock = jest.spyOn(core, "info");
     const failedMock = jest.spyOn(core, "setFailed");
     const stateMock = jest.spyOn(core, "saveState");
@@ -216,6 +217,9 @@ test("restore with no cache found", async () => {
 
     await run();
 
+    expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
+    expect(setCacheHitOutputMock).toHaveBeenCalledWith(false);
+
     expect(restoreCacheMock).toHaveBeenCalledTimes(1);
     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
 
@@ -237,6 +241,7 @@ test("restore with restore keys and no cache found", async () => {
         restoreKeys: [restoreKey]
     });
 
+    const setCacheHitOutputMock = jest.spyOn(actionUtils, "setCacheHitOutput");
     const infoMock = jest.spyOn(core, "info");
     const failedMock = jest.spyOn(core, "setFailed");
     const stateMock = jest.spyOn(core, "saveState");
@@ -248,6 +253,9 @@ test("restore with restore keys and no cache found", async () => {
 
     await run();
 
+    expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
+    expect(setCacheHitOutputMock).toHaveBeenCalledWith(false);
+
     expect(restoreCacheMock).toHaveBeenCalledTimes(1);
     expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]);
 
diff --git a/src/restore.ts b/src/restore.ts
index 5bc17fa..6c5cf1e 100644
--- a/src/restore.ts
+++ b/src/restore.ts
@@ -43,6 +43,7 @@ async function run(): Promise<void> {
                 ].join(", ")}`
             );
 
+            utils.setCacheHitOutput(false);
             return;
         }