1
0
Fork 0
mirror of https://code.forgejo.org/actions/cache.git synced 2025-04-30 07:19:54 +02:00

Use @actions/glob for pattern matching

This commit is contained in:
Ethan Dennis 2020-03-05 12:12:12 -08:00
parent 1e233443e8
commit db235cfc56
No known key found for this signature in database
GPG key ID: 32E74B75DB4065DD
12 changed files with 4427 additions and 176 deletions

View file

@ -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;