Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .licenses/npm/@actions/cache.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions __tests__/actionUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,26 @@ test("getInputAsInt throws if required and value missing", () => {
).toThrowError();
});

test("getInputAsBool returns false if input not set", () => {
expect(actionUtils.getInputAsBool("undefined")).toBe(false);
});

test("getInputAsBool returns value if input is valid", () => {
testUtils.setInput("foo", "true");
expect(actionUtils.getInputAsBool("foo")).toBe(true);
});

test("getInputAsBool returns false if input is invalid or NaN", () => {
testUtils.setInput("foo", "bar");
expect(actionUtils.getInputAsBool("foo")).toBe(false);
});

test("getInputAsBool throws if required and value missing", () => {
expect(() =>
actionUtils.getInputAsBool("undefined2", { required: true })
).toThrowError();
});

test("isCacheFeatureAvailable for ac enabled", () => {
jest.spyOn(cache, "isFeatureAvailable").mockImplementation(() => true);

Expand Down
40 changes: 32 additions & 8 deletions __tests__/restore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@ beforeAll(() => {
return actualUtils.getInputAsArray(name, options);
}
);

jest.spyOn(actionUtils, "getInputAsBool").mockImplementation(
(name, options) => {
const actualUtils = jest.requireActual("../src/utils/actionUtils");
return actualUtils.getInputAsBool(name, options);
}
);
});

beforeEach(() => {
jest.restoreAllMocks();
process.env[Events.Key] = Events.Push;
process.env[RefKey] = "refs/heads/feature-branch";

Expand All @@ -50,7 +58,8 @@ test("restore with no cache found", async () => {
const key = "node-test";
testUtils.setInputs({
path: path,
key
key,
enableCrossOsArchive: false
});

const infoMock = jest.spyOn(core, "info");
Expand All @@ -65,7 +74,7 @@ test("restore with no cache found", async () => {
await run();

expect(restoreCacheMock).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false);

expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
expect(stateMock).toHaveBeenCalledTimes(1);
Expand All @@ -84,7 +93,8 @@ test("restore with restore keys and no cache found", async () => {
testUtils.setInputs({
path: path,
key,
restoreKeys: [restoreKey]
restoreKeys: [restoreKey],
enableCrossOsArchive: false
});

const infoMock = jest.spyOn(core, "info");
Expand All @@ -99,7 +109,13 @@ test("restore with restore keys and no cache found", async () => {
await run();

expect(restoreCacheMock).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]);
expect(restoreCacheMock).toHaveBeenCalledWith(
[path],
key,
[restoreKey],
{},
false
);

expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
expect(stateMock).toHaveBeenCalledTimes(1);
Expand All @@ -116,7 +132,8 @@ test("restore with cache found for key", async () => {
const key = "node-test";
testUtils.setInputs({
path: path,
key
key,
enableCrossOsArchive: false
});

const infoMock = jest.spyOn(core, "info");
Expand All @@ -132,7 +149,7 @@ test("restore with cache found for key", async () => {
await run();

expect(restoreCacheMock).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false);

expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", key);
Expand All @@ -152,7 +169,8 @@ test("restore with cache found for restore key", async () => {
testUtils.setInputs({
path: path,
key,
restoreKeys: [restoreKey]
restoreKeys: [restoreKey],
enableCrossOsArchive: false
});

const infoMock = jest.spyOn(core, "info");
Expand All @@ -168,7 +186,13 @@ test("restore with cache found for restore key", async () => {
await run();

expect(restoreCacheMock).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]);
expect(restoreCacheMock).toHaveBeenCalledWith(
[path],
key,
[restoreKey],
{},
false
);

expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
expect(stateMock).toHaveBeenCalledWith("CACHE_RESULT", restoreKey);
Expand Down
66 changes: 50 additions & 16 deletions __tests__/restoreImpl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@ beforeAll(() => {
return actualUtils.getInputAsArray(name, options);
}
);

jest.spyOn(actionUtils, "getInputAsBool").mockImplementation(
(name, options) => {
const actualUtils = jest.requireActual("../src/utils/actionUtils");
return actualUtils.getInputAsBool(name, options);
}
);
});

beforeEach(() => {
jest.restoreAllMocks();
process.env[Events.Key] = Events.Push;
process.env[RefKey] = "refs/heads/feature-branch";

Expand Down Expand Up @@ -97,7 +105,8 @@ test("restore on GHES with AC available ", async () => {
const key = "node-test";
testUtils.setInputs({
path: path,
key
key,
enableCrossOsArchive: false
});

const infoMock = jest.spyOn(core, "info");
Expand All @@ -113,7 +122,7 @@ test("restore on GHES with AC available ", async () => {
await run(new StateProvider());

expect(restoreCacheMock).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false);

expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -152,13 +161,20 @@ test("restore with too many keys should fail", async () => {
testUtils.setInputs({
path: path,
key,
restoreKeys
restoreKeys,
enableCrossOsArchive: false
});
const failedMock = jest.spyOn(core, "setFailed");
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
await run(new StateProvider());
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, restoreKeys);
expect(restoreCacheMock).toHaveBeenCalledWith(
[path],
key,
restoreKeys,
{},
false
);
expect(failedMock).toHaveBeenCalledWith(
`Key Validation Error: Keys are limited to a maximum of 10.`
);
Expand All @@ -169,13 +185,14 @@ test("restore with large key should fail", async () => {
const key = "foo".repeat(512); // Over the 512 character limit
testUtils.setInputs({
path: path,
key
key,
enableCrossOsArchive: false
});
const failedMock = jest.spyOn(core, "setFailed");
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
await run(new StateProvider());
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false);
expect(failedMock).toHaveBeenCalledWith(
`Key Validation Error: ${key} cannot be larger than 512 characters.`
);
Expand All @@ -186,13 +203,14 @@ test("restore with invalid key should fail", async () => {
const key = "comma,comma";
testUtils.setInputs({
path: path,
key
key,
enableCrossOsArchive: false
});
const failedMock = jest.spyOn(core, "setFailed");
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
await run(new StateProvider());
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false);
expect(failedMock).toHaveBeenCalledWith(
`Key Validation Error: ${key} cannot contain commas.`
);
Expand All @@ -203,7 +221,8 @@ test("restore with no cache found", async () => {
const key = "node-test";
testUtils.setInputs({
path: path,
key
key,
enableCrossOsArchive: false
});

const infoMock = jest.spyOn(core, "info");
Expand All @@ -218,7 +237,7 @@ test("restore with no cache found", async () => {
await run(new StateProvider());

expect(restoreCacheMock).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false);

expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
expect(failedMock).toHaveBeenCalledTimes(0);
Expand All @@ -235,7 +254,8 @@ test("restore with restore keys and no cache found", async () => {
testUtils.setInputs({
path: path,
key,
restoreKeys: [restoreKey]
restoreKeys: [restoreKey],
enableCrossOsArchive: false
});

const infoMock = jest.spyOn(core, "info");
Expand All @@ -250,7 +270,13 @@ test("restore with restore keys and no cache found", async () => {
await run(new StateProvider());

expect(restoreCacheMock).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]);
expect(restoreCacheMock).toHaveBeenCalledWith(
[path],
key,
[restoreKey],
{},
false
);

expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
expect(failedMock).toHaveBeenCalledTimes(0);
Expand All @@ -265,7 +291,8 @@ test("restore with cache found for key", async () => {
const key = "node-test";
testUtils.setInputs({
path: path,
key
key,
enableCrossOsArchive: false
});

const infoMock = jest.spyOn(core, "info");
Expand All @@ -281,7 +308,7 @@ test("restore with cache found for key", async () => {
await run(new StateProvider());

expect(restoreCacheMock).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, []);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [], {}, false);

expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
Expand All @@ -298,7 +325,8 @@ test("restore with cache found for restore key", async () => {
testUtils.setInputs({
path: path,
key,
restoreKeys: [restoreKey]
restoreKeys: [restoreKey],
enableCrossOsArchive: false
});

const infoMock = jest.spyOn(core, "info");
Expand All @@ -314,7 +342,13 @@ test("restore with cache found for restore key", async () => {
await run(new StateProvider());

expect(restoreCacheMock).toHaveBeenCalledTimes(1);
expect(restoreCacheMock).toHaveBeenCalledWith([path], key, [restoreKey]);
expect(restoreCacheMock).toHaveBeenCalledWith(
[path],
key,
[restoreKey],
{},
false
);

expect(stateMock).toHaveBeenCalledWith("CACHE_KEY", key);
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
Expand Down
Loading