mirror of
https://github.com/actions/cache.git
synced 2026-07-04 06:09:31 +00:00
Implemented
This commit is contained in:
parent
88522ab9f3
commit
f12187b90c
29 changed files with 272142 additions and 230372 deletions
|
|
@ -1,12 +1,12 @@
|
|||
import * as cache from "@actions/cache";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import * as cache from "../src/backend";
|
||||
import { Events, RefKey } from "../src/constants";
|
||||
import * as actionUtils from "../src/utils/actionUtils";
|
||||
import * as testUtils from "../src/utils/testUtils";
|
||||
|
||||
jest.mock("@actions/core");
|
||||
jest.mock("@actions/cache");
|
||||
jest.mock("../src/backend");
|
||||
|
||||
beforeAll(() => {
|
||||
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import * as cache from "@actions/cache";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import * as cache from "../src/backend";
|
||||
import { Events, RefKey } from "../src/constants";
|
||||
import run from "../src/restore";
|
||||
import * as actionUtils from "../src/utils/actionUtils";
|
||||
|
|
@ -81,7 +81,8 @@ test("restore with no cache found", async () => {
|
|||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
|
|
@ -124,7 +125,8 @@ test("restore with restore keys and no cache found", async () => {
|
|||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
|
|
@ -166,7 +168,8 @@ test("restore with cache found for key", async () => {
|
|||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
|
|
@ -211,7 +214,8 @@ test("restore with cache found for restore key", async () => {
|
|||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
|
|
@ -256,7 +260,8 @@ test("Fail restore when fail on cache miss is enabled and primary + restore keys
|
|||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
|
|
@ -299,7 +304,8 @@ test("restore when fail on cache miss is enabled and primary key doesn't match r
|
|||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
|
|
@ -345,7 +351,8 @@ test("restore with fail on cache miss disabled and no cache found", async () =>
|
|||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import * as cache from "@actions/cache";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import * as cache from "../src/backend";
|
||||
import { Events, Inputs, RefKey } from "../src/constants";
|
||||
import run from "../src/restoreImpl";
|
||||
import { StateProvider } from "../src/stateProvider";
|
||||
|
|
@ -129,7 +129,8 @@ test("restore on GHES with AC available ", async () => {
|
|||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
|
|
@ -183,7 +184,8 @@ test("restore with too many keys should fail", async () => {
|
|||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
expect(failedMock).toHaveBeenCalledWith(
|
||||
`Key Validation Error: Keys are limited to a maximum of 10.`
|
||||
|
|
@ -209,7 +211,8 @@ test("restore with large key should fail", async () => {
|
|||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
expect(failedMock).toHaveBeenCalledWith(
|
||||
`Key Validation Error: ${key} cannot be larger than 512 characters.`
|
||||
|
|
@ -235,7 +238,8 @@ test("restore with invalid key should fail", async () => {
|
|||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
expect(failedMock).toHaveBeenCalledWith(
|
||||
`Key Validation Error: ${key} cannot contain commas.`
|
||||
|
|
@ -270,7 +274,8 @@ test("restore with no cache found", async () => {
|
|||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
|
|
@ -311,7 +316,8 @@ test("restore with restore keys and no cache found", async () => {
|
|||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
|
|
@ -351,7 +357,8 @@ test("restore with cache found for key", async () => {
|
|||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
|
|
@ -393,7 +400,8 @@ test("restore with cache found for restore key", async () => {
|
|||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
|
|
@ -434,7 +442,8 @@ test("restore with lookup-only set", async () => {
|
|||
{
|
||||
lookupOnly: true
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import * as cache from "@actions/cache";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import * as cache from "../src/backend";
|
||||
import { Events, RefKey } from "../src/constants";
|
||||
import run from "../src/restoreOnly";
|
||||
import * as actionUtils from "../src/utils/actionUtils";
|
||||
|
|
@ -82,7 +82,8 @@ test("restore with no cache found", async () => {
|
|||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||
|
|
@ -124,7 +125,8 @@ test("restore with restore keys and no cache found", async () => {
|
|||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||
|
|
@ -163,7 +165,8 @@ test("restore with cache found for key", async () => {
|
|||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||
|
|
@ -206,7 +209,8 @@ test("restore with cache found for restore key", async () => {
|
|||
{
|
||||
lookupOnly: false
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(outputMock).toHaveBeenCalledWith("cache-primary-key", key);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import * as cache from "@actions/cache";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import * as cache from "../src/backend";
|
||||
import { Events, Inputs, RefKey } from "../src/constants";
|
||||
import run from "../src/save";
|
||||
import * as actionUtils from "../src/utils/actionUtils";
|
||||
import * as testUtils from "../src/utils/testUtils";
|
||||
|
||||
jest.mock("@actions/core");
|
||||
jest.mock("@actions/cache");
|
||||
jest.mock("../src/backend");
|
||||
jest.mock("../src/utils/actionUtils");
|
||||
|
||||
beforeAll(() => {
|
||||
|
|
@ -109,7 +109,8 @@ test("save with valid inputs uploads a cache", async () => {
|
|||
{
|
||||
uploadChunkSize: 4000000
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import * as cache from "@actions/cache";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import * as cache from "../src/backend";
|
||||
import { Events, Inputs, RefKey } from "../src/constants";
|
||||
import run from "../src/saveImpl";
|
||||
import { StateProvider } from "../src/stateProvider";
|
||||
|
|
@ -8,7 +8,7 @@ import * as actionUtils from "../src/utils/actionUtils";
|
|||
import * as testUtils from "../src/utils/testUtils";
|
||||
|
||||
jest.mock("@actions/core");
|
||||
jest.mock("@actions/cache");
|
||||
jest.mock("../src/backend");
|
||||
jest.mock("../src/utils/actionUtils");
|
||||
|
||||
beforeAll(() => {
|
||||
|
|
@ -170,7 +170,8 @@ test("save on GHES with AC available", async () => {
|
|||
{
|
||||
uploadChunkSize: 4000000
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
|
|
@ -266,7 +267,8 @@ test("save with large cache outputs warning", async () => {
|
|||
[inputPath],
|
||||
primaryKey,
|
||||
expect.anything(),
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
||||
|
|
@ -299,7 +301,7 @@ test("save with reserve cache failure outputs warning", async () => {
|
|||
const saveCacheMock = jest
|
||||
.spyOn(cache, "saveCache")
|
||||
.mockImplementationOnce(() => {
|
||||
const actualCache = jest.requireActual("@actions/cache");
|
||||
const actualCache = jest.requireActual("../src/backend");
|
||||
const error = new actualCache.ReserveCacheError(
|
||||
`Unable to reserve cache with key ${primaryKey}, another job may be creating this cache.`
|
||||
);
|
||||
|
|
@ -313,7 +315,8 @@ test("save with reserve cache failure outputs warning", async () => {
|
|||
[inputPath],
|
||||
primaryKey,
|
||||
expect.anything(),
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(logWarningMock).toHaveBeenCalledWith(
|
||||
|
|
@ -356,7 +359,8 @@ test("save with server error outputs warning", async () => {
|
|||
[inputPath],
|
||||
primaryKey,
|
||||
expect.anything(),
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
||||
|
|
@ -401,7 +405,8 @@ test("save with valid inputs uploads a cache", async () => {
|
|||
{
|
||||
uploadChunkSize: 4000000
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import * as cache from "@actions/cache";
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import * as cache from "../src/backend";
|
||||
import { Events, Inputs, RefKey } from "../src/constants";
|
||||
import run from "../src/saveOnly";
|
||||
import * as actionUtils from "../src/utils/actionUtils";
|
||||
import * as testUtils from "../src/utils/testUtils";
|
||||
|
||||
jest.mock("@actions/core");
|
||||
jest.mock("@actions/cache");
|
||||
jest.mock("../src/backend");
|
||||
jest.mock("../src/utils/actionUtils");
|
||||
|
||||
beforeAll(() => {
|
||||
|
|
@ -99,7 +99,8 @@ test("save with valid inputs uploads a cache", async () => {
|
|||
{
|
||||
uploadChunkSize: 4000000
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
|
|
@ -131,7 +132,8 @@ test("save failing logs the warning message", async () => {
|
|||
{
|
||||
uploadChunkSize: 4000000
|
||||
},
|
||||
false
|
||||
{ credentials: { accessKeyId: "", secretAccessKey: "" }, region: "" },
|
||||
""
|
||||
);
|
||||
|
||||
expect(warningMock).toHaveBeenCalledTimes(1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue