mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-05-05 09:39:54 +02:00
Add initial minimatch support
This commit is contained in:
parent
84cead4a82
commit
1e233443e8
14 changed files with 202 additions and 108 deletions
|
@ -1,5 +1,4 @@
|
|||
import * as core from "@actions/core";
|
||||
import * as os from "os";
|
||||
import * as path from "path";
|
||||
|
||||
import { Events, Outputs, State } from "../src/constants";
|
||||
|
@ -181,42 +180,6 @@ test("isValidEvent returns false for unknown event", () => {
|
|||
expect(isValidEvent).toBe(false);
|
||||
});
|
||||
|
||||
test("resolvePath with no ~ in path", () => {
|
||||
const filePath = ".cache/yarn";
|
||||
|
||||
const resolvedPath = actionUtils.resolvePath(filePath);
|
||||
|
||||
const expectedPath = path.resolve(filePath);
|
||||
expect(resolvedPath).toBe(expectedPath);
|
||||
});
|
||||
|
||||
test("resolvePath 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.resolvePath(filePath);
|
||||
|
||||
const expectedPath = path.join(homedir, ".cache/yarn");
|
||||
expect(resolvedPath).toBe(expectedPath);
|
||||
});
|
||||
|
||||
test("resolvePath with home not found", () => {
|
||||
const filePath = "~/.cache/yarn";
|
||||
const homedirMock = jest.spyOn(os, "homedir");
|
||||
homedirMock.mockImplementation(() => {
|
||||
return "";
|
||||
});
|
||||
|
||||
expect(() => actionUtils.resolvePath(filePath)).toThrow(
|
||||
"Unable to resolve `~` to HOME"
|
||||
);
|
||||
});
|
||||
|
||||
test("isValidEvent returns true for push event", () => {
|
||||
const event = Events.Push;
|
||||
process.env[Events.Key] = event;
|
||||
|
|
42
__tests__/pathUtils.test.ts
Normal file
42
__tests__/pathUtils.test.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
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,15 +7,17 @@ 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(actionUtils, "resolvePath").mockImplementation(filePath => {
|
||||
return path.resolve(filePath);
|
||||
});
|
||||
// jest.spyOn(pathUtils, "expandPaths").mockImplementation(filePaths => {
|
||||
// return filePaths.map(x => path.resolve(x));
|
||||
// });
|
||||
|
||||
jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation(
|
||||
(key, cacheResult) => {
|
||||
|
|
|
@ -7,11 +7,13 @@ 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) => {
|
||||
|
@ -40,8 +42,8 @@ beforeAll(() => {
|
|||
return actualUtils.getSupportedEvents();
|
||||
});
|
||||
|
||||
jest.spyOn(actionUtils, "resolvePath").mockImplementation(filePath => {
|
||||
return path.resolve(filePath);
|
||||
jest.spyOn(pathUtils, "expandPaths").mockImplementation(filePaths => {
|
||||
return filePaths.map(x => path.resolve(x));
|
||||
});
|
||||
|
||||
jest.spyOn(actionUtils, "createTempDirectory").mockImplementation(() => {
|
||||
|
|
|
@ -14,7 +14,7 @@ beforeAll(() => {
|
|||
});
|
||||
|
||||
afterAll(() => {
|
||||
process.env["GITHUB_WORKSPACE"] = undefined;
|
||||
delete process.env["GITHUB_WORKSPACE"];
|
||||
});
|
||||
|
||||
test("extract tar", async () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue