|
|
@ -2,8 +2,7 @@ import * as cache from "@actions/cache";
|
|
|
|
import * as core from "@actions/core";
|
|
|
|
import * as core from "@actions/core";
|
|
|
|
|
|
|
|
|
|
|
|
import { Events, RefKey } from "../src/constants";
|
|
|
|
import { Events, RefKey } from "../src/constants";
|
|
|
|
import run from "../src/restoreImpl";
|
|
|
|
import run from "../src/restoreOnly";
|
|
|
|
import { StateProvider } from "../src/stateProvider";
|
|
|
|
|
|
|
|
import * as actionUtils from "../src/utils/actionUtils";
|
|
|
|
import * as actionUtils from "../src/utils/actionUtils";
|
|
|
|
import * as testUtils from "../src/utils/testUtils";
|
|
|
|
import * as testUtils from "../src/utils/testUtils";
|
|
|
|
|
|
|
|
|
|
|
@ -56,19 +55,20 @@ test("restore with no cache found", async () => {
|
|
|
|
|
|
|
|
|
|
|
|
const infoMock = jest.spyOn(core, "info");
|
|
|
|
const infoMock = jest.spyOn(core, "info");
|
|
|
|
const failedMock = jest.spyOn(core, "setFailed");
|
|
|
|
const failedMock = jest.spyOn(core, "setFailed");
|
|
|
|
const stateMock = jest.spyOn(core, "saveState");
|
|
|
|
const outputMock = jest.spyOn(core, "setOutput");
|
|
|
|
const restoreCacheMock = jest
|
|
|
|
const restoreCacheMock = jest
|
|
|
|
.spyOn(cache, "restoreCache")
|
|
|
|
.spyOn(cache, "restoreCache")
|
|
|
|
.mockImplementationOnce(() => {
|
|
|
|
.mockImplementationOnce(() => {
|
|
|
|
return Promise.resolve(undefined);
|
|
|
|
return Promise.resolve(undefined);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
await run(new StateProvider());
|
|
|
|
await run();
|
|
|
|
|
|
|
|
|
|
|
|
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
|
|
|
|
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
|
|
|
|
|
|
|
|
|
|
|
|
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
|
|
|
expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
|
|
|
|
|
|
|
expect(outputMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
|
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
|
|
|
|
|
|
|
|
|
|
expect(infoMock).toHaveBeenCalledWith(
|
|
|
|
expect(infoMock).toHaveBeenCalledWith(
|
|
|
@ -88,19 +88,19 @@ test("restore with restore keys and no cache found", async () => {
|
|
|
|
|
|
|
|
|
|
|
|
const infoMock = jest.spyOn(core, "info");
|
|
|
|
const infoMock = jest.spyOn(core, "info");
|
|
|
|
const failedMock = jest.spyOn(core, "setFailed");
|
|
|
|
const failedMock = jest.spyOn(core, "setFailed");
|
|
|
|
const stateMock = jest.spyOn(core, "saveState");
|
|
|
|
const outputMock = jest.spyOn(core, "setOutput");
|
|
|
|
const restoreCacheMock = jest
|
|
|
|
const restoreCacheMock = jest
|
|
|
|
.spyOn(cache, "restoreCache")
|
|
|
|
.spyOn(cache, "restoreCache")
|
|
|
|
.mockImplementationOnce(() => {
|
|
|
|
.mockImplementationOnce(() => {
|
|
|
|
return Promise.resolve(undefined);
|
|
|
|
return Promise.resolve(undefined);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
await run(new StateProvider());
|
|
|
|
await run();
|
|
|
|
|
|
|
|
|
|
|
|
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]);
|
|
|
|
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]);
|
|
|
|
|
|
|
|
|
|
|
|
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
|
|
|
expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
|
|
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
|
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
|
|
|
|
|
|
|
|
|
|
expect(infoMock).toHaveBeenCalledWith(
|
|
|
|
expect(infoMock).toHaveBeenCalledWith(
|
|
|
@ -118,22 +118,23 @@ test("restore with cache found for key", async () => {
|
|
|
|
|
|
|
|
|
|
|
|
const infoMock = jest.spyOn(core, "info");
|
|
|
|
const infoMock = jest.spyOn(core, "info");
|
|
|
|
const failedMock = jest.spyOn(core, "setFailed");
|
|
|
|
const failedMock = jest.spyOn(core, "setFailed");
|
|
|
|
const stateMock = jest.spyOn(core, "saveState");
|
|
|
|
const outputMock = jest.spyOn(core, "setOutput");
|
|
|
|
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
|
|
|
|
|
|
|
const restoreCacheMock = jest
|
|
|
|
const restoreCacheMock = jest
|
|
|
|
.spyOn(cache, "restoreCache")
|
|
|
|
.spyOn(cache, "restoreCache")
|
|
|
|
.mockImplementationOnce(() => {
|
|
|
|
.mockImplementationOnce(() => {
|
|
|
|
return Promise.resolve(key);
|
|
|
|
return Promise.resolve(key);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
await run(new StateProvider());
|
|
|
|
await run();
|
|
|
|
|
|
|
|
|
|
|
|
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
|
|
|
|
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
|
|
|
|
|
|
|
|
|
|
|
|
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
|
|
|
expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
|
|
|
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(outputMock).toHaveBeenCalledWith("cache-hit", "true");
|
|
|
|
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "true");
|
|
|
|
expect(outputMock).toHaveBeenCalledWith("cache-restore-key", key);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(outputMock).toHaveBeenCalledTimes(3);
|
|
|
|
|
|
|
|
|
|
|
|
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
|
|
|
expect(infoMock).toHaveBeenCalledWith(`Cache restored from key: ${key}`);
|
|
|
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
|
|
expect(failedMock).toHaveBeenCalledTimes(0);
|
|
|
@ -151,22 +152,24 @@ test("restore with cache found for restore key", async () => {
|
|
|
|
|
|
|
|
|
|
|
|
const infoMock = jest.spyOn(core, "info");
|
|
|
|
const infoMock = jest.spyOn(core, "info");
|
|
|
|
const failedMock = jest.spyOn(core, "setFailed");
|
|
|
|
const failedMock = jest.spyOn(core, "setFailed");
|
|
|
|
const stateMock = jest.spyOn(core, "saveState");
|
|
|
|
const outputMock = jest.spyOn(core, "setOutput");
|
|
|
|
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
|
|
|
|
|
|
|
|
const restoreCacheMock = jest
|
|
|
|
const restoreCacheMock = jest
|
|
|
|
.spyOn(cache, "restoreCache")
|
|
|
|
.spyOn(cache, "restoreCache")
|
|
|
|
.mockImplementationOnce(() => {
|
|
|
|
.mockImplementationOnce(() => {
|
|
|
|
return Promise.resolve(restoreKey);
|
|
|
|
return Promise.resolve(restoreKey);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
await run(new StateProvider());
|
|
|
|
await run();
|
|
|
|
|
|
|
|
|
|
|
|
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]);
|
|
|
|
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]);
|
|
|
|
|
|
|
|
|
|
|
|
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
|
|
|
expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
|
|
|
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(outputMock).toHaveBeenCalledWith("cache-hit", "false");
|
|
|
|
expect(setCacheHitOutputMock).toHaveBeenCalledWith("cache-hit", "false");
|
|
|
|
expect(outputMock).toHaveBeenCalledWith("cache-restore-key", restoreKey);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(outputMock).toHaveBeenCalledTimes(3);
|
|
|
|
|
|
|
|
|
|
|
|
expect(infoMock).toHaveBeenCalledWith(
|
|
|
|
expect(infoMock).toHaveBeenCalledWith(
|
|
|
|
`Cache restored from key: ${restoreKey}`
|
|
|
|
`Cache restored from key: ${restoreKey}`
|
|
|
|
);
|
|
|
|
);
|
|
|
|