mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-04-24 05:09:54 +02:00
Improve string split
This commit is contained in:
parent
e561127c3e
commit
d60d2bef10
8 changed files with 95 additions and 27 deletions
|
@ -2,9 +2,16 @@ import * as core from "@actions/core";
|
|||
|
||||
import { Events, Outputs, RefKey, State } from "../src/constants";
|
||||
import * as actionUtils from "../src/utils/actionUtils";
|
||||
import * as testUtils from "../src/utils/testUtils";
|
||||
|
||||
jest.mock("@actions/core");
|
||||
|
||||
beforeAll(() => {
|
||||
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
|
||||
return jest.requireActual("@actions/core").getInput(name, options);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
delete process.env[Events.Key];
|
||||
delete process.env[RefKey];
|
||||
|
@ -157,3 +164,33 @@ test("isValidEvent returns true for event that has a ref", () => {
|
|||
|
||||
expect(isValidEvent).toBe(true);
|
||||
});
|
||||
|
||||
test("getInputAsArray returns empty array if not required and missing", () => {
|
||||
expect(actionUtils.getInputAsArray("foo")).toEqual([]);
|
||||
});
|
||||
|
||||
test("getInputAsArray throws error if required and missing", () => {
|
||||
expect(() =>
|
||||
actionUtils.getInputAsArray("foo", { required: true })
|
||||
).toThrowError();
|
||||
});
|
||||
|
||||
test("getInputAsArray handles single line correctly", () => {
|
||||
testUtils.setInput("foo", "bar");
|
||||
expect(actionUtils.getInputAsArray("foo")).toEqual(["bar"]);
|
||||
});
|
||||
|
||||
test("getInputAsArray handles multiple lines correctly", () => {
|
||||
testUtils.setInput("foo", "bar\nbaz");
|
||||
expect(actionUtils.getInputAsArray("foo")).toEqual(["bar", "baz"]);
|
||||
});
|
||||
|
||||
test("getInputAsArray handles different new lines correctly", () => {
|
||||
testUtils.setInput("foo", "bar\r\nbaz");
|
||||
expect(actionUtils.getInputAsArray("foo")).toEqual(["bar", "baz"]);
|
||||
});
|
||||
|
||||
test("getInputAsArray handles empty lines correctly", () => {
|
||||
testUtils.setInput("foo", "\n\nbar\n\nbaz\n\n");
|
||||
expect(actionUtils.getInputAsArray("foo")).toEqual(["bar", "baz"]);
|
||||
});
|
||||
|
|
|
@ -20,6 +20,13 @@ beforeAll(() => {
|
|||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
||||
return actualUtils.isValidEvent();
|
||||
});
|
||||
|
||||
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
|
||||
(name, options) => {
|
||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
||||
return actualUtils.getInputAsArray(name, options);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -19,6 +19,14 @@ beforeAll(() => {
|
|||
return jest.requireActual("../src/utils/actionUtils").getCacheState();
|
||||
});
|
||||
|
||||
jest.spyOn(actionUtils, "getInputAsArray").mockImplementation(
|
||||
(name, options) => {
|
||||
return jest
|
||||
.requireActual("../src/utils/actionUtils")
|
||||
.getInputAsArray(name, options);
|
||||
}
|
||||
);
|
||||
|
||||
jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation(
|
||||
(key, cacheResult) => {
|
||||
return jest
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue