2019-12-13 17:24:37 -05:00
|
|
|
import * as exec from "@actions/exec";
|
|
|
|
import * as io from "@actions/io";
|
|
|
|
import * as tar from "../src/tar";
|
|
|
|
|
|
|
|
jest.mock("@actions/exec");
|
|
|
|
jest.mock("@actions/io");
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
jest.spyOn(io, "which").mockImplementation(tool => {
|
|
|
|
return Promise.resolve(tool);
|
|
|
|
});
|
2020-03-04 16:02:51 -08:00
|
|
|
|
|
|
|
process.env["GITHUB_WORKSPACE"] = process.cwd();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
2020-03-05 09:15:35 -08:00
|
|
|
delete process.env["GITHUB_WORKSPACE"];
|
2019-12-13 17:24:37 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test("extract tar", async () => {
|
|
|
|
const mkdirMock = jest.spyOn(io, "mkdirP");
|
|
|
|
const execMock = jest.spyOn(exec, "exec");
|
|
|
|
|
|
|
|
const archivePath = "cache.tar";
|
2020-03-04 16:02:51 -08:00
|
|
|
const workspace = process.env["GITHUB_WORKSPACE"];
|
2019-12-13 17:24:37 -05:00
|
|
|
|
2020-03-04 16:02:51 -08:00
|
|
|
await tar.extractTar(archivePath);
|
|
|
|
|
|
|
|
expect(mkdirMock).toHaveBeenCalledWith(workspace);
|
2019-12-13 17:24:37 -05:00
|
|
|
|
|
|
|
const IS_WINDOWS = process.platform === "win32";
|
|
|
|
const tarPath = IS_WINDOWS
|
|
|
|
? `${process.env["windir"]}\\System32\\tar.exe`
|
|
|
|
: "tar";
|
|
|
|
expect(execMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(execMock).toHaveBeenCalledWith(`"${tarPath}"`, [
|
|
|
|
"-xz",
|
|
|
|
"-f",
|
|
|
|
archivePath,
|
2020-03-04 16:02:51 -08:00
|
|
|
"-P",
|
2019-12-13 17:24:37 -05:00
|
|
|
"-C",
|
2020-03-04 16:02:51 -08:00
|
|
|
workspace
|
2019-12-13 17:24:37 -05:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("create tar", async () => {
|
|
|
|
const execMock = jest.spyOn(exec, "exec");
|
|
|
|
|
|
|
|
const archivePath = "cache.tar";
|
2020-03-04 16:02:51 -08:00
|
|
|
const workspace = process.env["GITHUB_WORKSPACE"];
|
|
|
|
const sourceDirectories = ["~/.npm/cache", `${workspace}/dist`];
|
|
|
|
|
|
|
|
await tar.createTar(archivePath, sourceDirectories);
|
2019-12-13 17:24:37 -05:00
|
|
|
|
|
|
|
const IS_WINDOWS = process.platform === "win32";
|
|
|
|
const tarPath = IS_WINDOWS
|
|
|
|
? `${process.env["windir"]}\\System32\\tar.exe`
|
|
|
|
: "tar";
|
|
|
|
expect(execMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(execMock).toHaveBeenCalledWith(`"${tarPath}"`, [
|
|
|
|
"-cz",
|
|
|
|
"-f",
|
|
|
|
archivePath,
|
|
|
|
"-C",
|
2020-03-04 16:02:51 -08:00
|
|
|
workspace,
|
|
|
|
sourceDirectories.join(" ")
|
2019-12-13 17:24:37 -05:00
|
|
|
]);
|
|
|
|
});
|