Add a restore-only option to support pulling without saving a cache entry

This commit is contained in:
Jason T. Greene 2020-01-29 16:53:20 -05:00
parent e43776276f
commit e44e77f968
4 changed files with 56 additions and 1 deletions

View file

@ -376,3 +376,47 @@ test("save with valid inputs uploads a cache", async () => {
expect(failedMock).toHaveBeenCalledTimes(0);
});
test("save skipped with restore only", async () => {
const infoMock = jest.spyOn(core, "info");
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
const cacheEntry: ArtifactCacheEntry = {
cacheKey: "Linux-node-",
scope: "refs/heads/master",
creationTime: "2019-11-13T19:18:02+00:00",
archiveLocation: "www.actionscache.test/download"
};
jest.spyOn(core, "getState")
// Cache Entry State
.mockImplementationOnce(() => {
return JSON.stringify(cacheEntry);
})
// Cache Key State
.mockImplementationOnce(() => {
return primaryKey;
});
const inputPath = "node_modules";
testUtils.setInput(Inputs.Path, inputPath);
testUtils.setInput(Inputs.RestoreOnly, "true");
const cacheId = 4;
const reserveCacheMock = jest
.spyOn(cacheHttpClient, "reserveCache")
.mockImplementationOnce(() => {
return Promise.resolve(cacheId);
});
const saveCacheMock = jest.spyOn(cacheHttpClient, "saveCache");
await run();
expect(infoMock).toHaveBeenCalledWith(
"Cache action configured for restore-only, skipping save step"
);
expect(reserveCacheMock).toHaveBeenCalledTimes(0);
expect(saveCacheMock).toHaveBeenCalledTimes(0);
});