From bd756c16ae92a12b0d5c13f29c4e5d9003bdfa01 Mon Sep 17 00:00:00 2001 From: Ethan Dennis Date: Mon, 16 Mar 2020 09:19:53 -0700 Subject: [PATCH] Unit test getCacheVersion --- __tests__/cacheHttpsClient.test.ts | 37 ++++++++++++++++++++++++++++++ dist/restore/index.js | 7 +++--- dist/save/index.js | 7 +++--- src/cacheHttpClient.ts | 8 +++---- 4 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 __tests__/cacheHttpsClient.test.ts diff --git a/__tests__/cacheHttpsClient.test.ts b/__tests__/cacheHttpsClient.test.ts new file mode 100644 index 0000000..0fca5dd --- /dev/null +++ b/__tests__/cacheHttpsClient.test.ts @@ -0,0 +1,37 @@ +import * as testUtils from "../src/utils/testUtils"; +import { getCacheVersion } from "../src/cacheHttpClient"; + +afterEach(() => { + testUtils.clearInputs(); +}); + +test("getCacheVersion with no restore keys returns version", async () => { + testUtils.setInputs({ + path: "node-test", + key: "node_modules" + }); + + const result = getCacheVersion(); + + expect(result).toEqual( + "ee9d5dc2e8e2df8e32f62c367796abefc134790584015d8e1207523c9085e87e" + ); +}); + +test("getCacheVersion with restore keys returns version", async () => { + testUtils.setInputs({ + path: "node-test", + key: "node_modules", + restoreKeys: ["node-", "node"] + }); + + const result = getCacheVersion(); + + expect(result).toEqual( + "b8596b1e42c34a25be7b43c7b91892ed3ba81cba1e075365f408b35dbfabb61b" + ); +}); + +test("getCacheVersion with no input throws", async () => { + expect(() => getCacheVersion()).toThrow(); +}); diff --git a/dist/restore/index.js b/dist/restore/index.js index 1cd4d25..64232e4 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -2237,9 +2237,9 @@ function createHttpClient() { function getCacheVersion() { // Add salt to cache version to support breaking changes in cache entry const components = [ - core.getInput(constants_1.Inputs.Key), - core.getInput(constants_1.Inputs.RestoreKeys), - core.getInput(constants_1.Inputs.Path), + core.getInput(constants_1.Inputs.Key, { required: true }), + core.getInput(constants_1.Inputs.RestoreKeys, { required: false }), + core.getInput(constants_1.Inputs.Path, { required: true }), versionSalt ]; return crypto @@ -2247,6 +2247,7 @@ function getCacheVersion() { .update(components.join("|")) .digest("hex"); } +exports.getCacheVersion = getCacheVersion; function getCacheEntry() { var _a; return __awaiter(this, void 0, void 0, function* () { diff --git a/dist/save/index.js b/dist/save/index.js index e5ebd56..6f45755 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -2237,9 +2237,9 @@ function createHttpClient() { function getCacheVersion() { // Add salt to cache version to support breaking changes in cache entry const components = [ - core.getInput(constants_1.Inputs.Key), - core.getInput(constants_1.Inputs.RestoreKeys), - core.getInput(constants_1.Inputs.Path), + core.getInput(constants_1.Inputs.Key, { required: true }), + core.getInput(constants_1.Inputs.RestoreKeys, { required: false }), + core.getInput(constants_1.Inputs.Path, { required: true }), versionSalt ]; return crypto @@ -2247,6 +2247,7 @@ function getCacheVersion() { .update(components.join("|")) .digest("hex"); } +exports.getCacheVersion = getCacheVersion; function getCacheEntry() { var _a; return __awaiter(this, void 0, void 0, function* () { diff --git a/src/cacheHttpClient.ts b/src/cacheHttpClient.ts index d3cfd6c..d00355a 100644 --- a/src/cacheHttpClient.ts +++ b/src/cacheHttpClient.ts @@ -81,12 +81,12 @@ function createHttpClient(): HttpClient { ); } -function getCacheVersion(): string { +export function getCacheVersion(): string { // Add salt to cache version to support breaking changes in cache entry const components = [ - core.getInput(Inputs.Key), - core.getInput(Inputs.RestoreKeys), - core.getInput(Inputs.Path), + core.getInput(Inputs.Key, { required: true }), + core.getInput(Inputs.RestoreKeys, { required: false }), + core.getInput(Inputs.Path, { required: true }), versionSalt ];