mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-05-05 09:39:54 +02:00
Use @actions/glob for pattern matching
This commit is contained in:
parent
1e233443e8
commit
db235cfc56
12 changed files with 4427 additions and 176 deletions
|
@ -1,4 +1,5 @@
|
|||
import * as core from "@actions/core";
|
||||
import * as os from "os";
|
||||
import * as path from "path";
|
||||
|
||||
import { Events, Outputs, State } from "../src/constants";
|
||||
|
@ -180,6 +181,42 @@ test("isValidEvent returns false for unknown event", () => {
|
|||
expect(isValidEvent).toBe(false);
|
||||
});
|
||||
|
||||
test("expandPaths with no ~ in path", () => {
|
||||
const filePath = ".cache/yarn";
|
||||
|
||||
const resolvedPath = actionUtils.expandPaths([filePath]);
|
||||
|
||||
const expectedPath = [path.resolve(filePath)];
|
||||
expect(resolvedPath).toStrictEqual(expectedPath);
|
||||
});
|
||||
|
||||
test("expandPaths with ~ in path", () => {
|
||||
const filePath = "~/.cache/yarn";
|
||||
|
||||
const homedir = jest.requireActual("os").homedir();
|
||||
const homedirMock = jest.spyOn(os, "homedir");
|
||||
homedirMock.mockImplementation(() => {
|
||||
return homedir;
|
||||
});
|
||||
|
||||
const resolvedPath = actionUtils.expandPaths([filePath]);
|
||||
|
||||
const expectedPath = [path.join(homedir, ".cache/yarn")];
|
||||
expect(resolvedPath).toStrictEqual(expectedPath);
|
||||
});
|
||||
|
||||
test("expandPaths with home not found", () => {
|
||||
const filePath = "~/.cache/yarn";
|
||||
const homedirMock = jest.spyOn(os, "homedir");
|
||||
homedirMock.mockImplementation(() => {
|
||||
return "";
|
||||
});
|
||||
|
||||
expect(() => actionUtils.expandPaths([filePath])).toThrow(
|
||||
"Unable to resolve `~` to HOME"
|
||||
);
|
||||
});
|
||||
|
||||
test("isValidEvent returns true for push event", () => {
|
||||
const event = Events.Push;
|
||||
process.env[Events.Key] = event;
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
import * as path from "path";
|
||||
import * as os from "os";
|
||||
import * as pathUtils from "../src/utils/pathUtils";
|
||||
|
||||
jest.mock("@actions/core");
|
||||
jest.mock("os");
|
||||
|
||||
test("expandPaths with no ~ in path", () => {
|
||||
const filePath = ".cache/yarn";
|
||||
|
||||
const resolvedPath = pathUtils.expandPaths([filePath]);
|
||||
|
||||
const expectedPath = [path.resolve(filePath)];
|
||||
expect(resolvedPath).toStrictEqual(expectedPath);
|
||||
});
|
||||
|
||||
test("expandPaths with ~ in path", () => {
|
||||
const filePath = "~/.cache/yarn";
|
||||
|
||||
const homedir = jest.requireActual("os").homedir();
|
||||
const homedirMock = jest.spyOn(os, "homedir");
|
||||
homedirMock.mockImplementation(() => {
|
||||
return homedir;
|
||||
});
|
||||
|
||||
const resolvedPath = pathUtils.expandPaths([filePath]);
|
||||
|
||||
const expectedPath = [path.join(homedir, ".cache/yarn")];
|
||||
expect(resolvedPath).toStrictEqual(expectedPath);
|
||||
});
|
||||
|
||||
test("expandPaths with home not found", () => {
|
||||
const filePath = "~/.cache/yarn";
|
||||
const homedirMock = jest.spyOn(os, "homedir");
|
||||
homedirMock.mockImplementation(() => {
|
||||
return "";
|
||||
});
|
||||
|
||||
expect(() => pathUtils.expandPaths([filePath])).toThrow(
|
||||
"Unable to resolve `~` to HOME"
|
||||
);
|
||||
});
|
|
@ -7,18 +7,12 @@ import run from "../src/restore";
|
|||
import * as tar from "../src/tar";
|
||||
import * as actionUtils from "../src/utils/actionUtils";
|
||||
import * as testUtils from "../src/utils/testUtils";
|
||||
// import * as pathUtils from "../src/utils/pathUtils";
|
||||
|
||||
jest.mock("../src/cacheHttpClient");
|
||||
jest.mock("../src/tar");
|
||||
jest.mock("../src/utils/actionUtils");
|
||||
// jest.mock("../src/utils/pathUtils");
|
||||
|
||||
beforeAll(() => {
|
||||
// jest.spyOn(pathUtils, "expandPaths").mockImplementation(filePaths => {
|
||||
// return filePaths.map(x => path.resolve(x));
|
||||
// });
|
||||
|
||||
jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation(
|
||||
(key, cacheResult) => {
|
||||
const actualUtils = jest.requireActual("../src/utils/actionUtils");
|
||||
|
|
|
@ -7,13 +7,11 @@ import run from "../src/save";
|
|||
import * as tar from "../src/tar";
|
||||
import * as actionUtils from "../src/utils/actionUtils";
|
||||
import * as testUtils from "../src/utils/testUtils";
|
||||
import * as pathUtils from "../src/utils/pathUtils";
|
||||
|
||||
jest.mock("@actions/core");
|
||||
jest.mock("../src/cacheHttpClient");
|
||||
jest.mock("../src/tar");
|
||||
jest.mock("../src/utils/actionUtils");
|
||||
jest.mock("../src/utils/pathUtils");
|
||||
|
||||
beforeAll(() => {
|
||||
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
|
||||
|
@ -42,9 +40,11 @@ beforeAll(() => {
|
|||
return actualUtils.getSupportedEvents();
|
||||
});
|
||||
|
||||
jest.spyOn(pathUtils, "expandPaths").mockImplementation(filePaths => {
|
||||
return filePaths.map(x => path.resolve(x));
|
||||
});
|
||||
jest.spyOn(actionUtils, "expandPaths").mockImplementation(
|
||||
async filePaths => {
|
||||
return filePaths.map(x => path.resolve(x));
|
||||
}
|
||||
);
|
||||
|
||||
jest.spyOn(actionUtils, "createTempDirectory").mockImplementation(() => {
|
||||
return Promise.resolve("/foo/bar");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue