Fallback to which tar if no system tar

This commit is contained in:
Josh Gross 2019-12-13 17:01:05 -05:00
parent 6199b9ad63
commit 1569e37d6f
2 changed files with 26 additions and 18 deletions

View file

@ -6,17 +6,11 @@ jest.mock("@actions/exec");
jest.mock("@actions/io");
beforeAll(() => {
process.env["windir"] = "C:";
jest.spyOn(io, "which").mockImplementation(tool => {
return Promise.resolve(tool);
});
});
afterAll(() => {
delete process.env["windir"];
});
test("extract tar", async () => {
const mkdirMock = jest.spyOn(io, "mkdirP");
const execMock = jest.spyOn(exec, "exec");
@ -28,7 +22,7 @@ test("extract tar", async () => {
expect(mkdirMock).toHaveBeenCalledWith(targetDirectory);
const IS_WINDOWS = process.platform === "win32";
const tarPath = IS_WINDOWS ? "C:\\System32\\tar.exe" : "tar";
const tarPath = IS_WINDOWS ? `${process.env["windir"]}\\System32\\tar.exe` : "tar";
expect(execMock).toHaveBeenCalledTimes(1);
expect(execMock).toHaveBeenCalledWith(`"${tarPath}"`, [
"-xz",
@ -47,7 +41,7 @@ test("create tar", async () => {
await tar.createTar(archivePath, sourceDirectory);
const IS_WINDOWS = process.platform === "win32";
const tarPath = IS_WINDOWS ? "C:\\System32\\tar.exe" : "tar";
const tarPath = IS_WINDOWS ? `${process.env["windir"]}\\System32\\tar.exe` : "tar";
expect(execMock).toHaveBeenCalledTimes(1);
expect(execMock).toHaveBeenCalledWith(`"${tarPath}"`, [
"-cz",