mirror of
https://github.com/actions/cache.git
synced 2025-04-22 12:06:45 +00:00
Use BSD tar on windows
This commit is contained in:
parent
3d01b4eb53
commit
7352daed78
6 changed files with 117 additions and 163 deletions
|
@ -1,19 +1,17 @@
|
|||
import * as core from "@actions/core";
|
||||
import * as exec from "@actions/exec";
|
||||
import * as io from "@actions/io";
|
||||
import * as path from "path";
|
||||
import * as cacheHttpClient from "../src/cacheHttpClient";
|
||||
import { Events, Inputs } from "../src/constants";
|
||||
import { ArtifactCacheEntry } from "../src/contracts";
|
||||
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";
|
||||
|
||||
jest.mock("@actions/core");
|
||||
jest.mock("@actions/exec");
|
||||
jest.mock("@actions/io");
|
||||
jest.mock("../src/utils/actionUtils");
|
||||
jest.mock("../src/cacheHttpClient");
|
||||
jest.mock("../src/tar");
|
||||
jest.mock("../src/utils/actionUtils");
|
||||
|
||||
beforeAll(() => {
|
||||
jest.spyOn(core, "getInput").mockImplementation((name, options) => {
|
||||
|
@ -49,10 +47,6 @@ beforeAll(() => {
|
|||
jest.spyOn(actionUtils, "createTempDirectory").mockImplementation(() => {
|
||||
return Promise.resolve("/foo/bar");
|
||||
});
|
||||
|
||||
jest.spyOn(io, "which").mockImplementation(tool => {
|
||||
return Promise.resolve(tool);
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -128,7 +122,7 @@ test("save with exact match returns early", async () => {
|
|||
return primaryKey;
|
||||
});
|
||||
|
||||
const execMock = jest.spyOn(exec, "exec");
|
||||
const createTarMock = jest.spyOn(tar, "createTar");
|
||||
|
||||
await run();
|
||||
|
||||
|
@ -136,7 +130,7 @@ test("save with exact match returns early", async () => {
|
|||
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
||||
);
|
||||
|
||||
expect(execMock).toHaveBeenCalledTimes(0);
|
||||
expect(createTarMock).toHaveBeenCalledTimes(0);
|
||||
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
@ -198,7 +192,7 @@ test("save with large cache outputs warning", async () => {
|
|||
const cachePath = path.resolve(inputPath);
|
||||
testUtils.setInput(Inputs.Path, inputPath);
|
||||
|
||||
const execMock = jest.spyOn(exec, "exec");
|
||||
const createTarMock = jest.spyOn(tar, "createTar");
|
||||
|
||||
const cacheSize = 1024 * 1024 * 1024; //~1GB, over the 400MB limit
|
||||
jest.spyOn(actionUtils, "getArchiveFileSize").mockImplementationOnce(() => {
|
||||
|
@ -209,21 +203,8 @@ test("save with large cache outputs warning", async () => {
|
|||
|
||||
const archivePath = path.join("/foo/bar", "cache.tgz");
|
||||
|
||||
const IS_WINDOWS = process.platform === "win32";
|
||||
const args = IS_WINDOWS
|
||||
? [
|
||||
"-cz",
|
||||
"--force-local",
|
||||
"-f",
|
||||
archivePath.replace(/\\/g, "/"),
|
||||
"-C",
|
||||
cachePath.replace(/\\/g, "/"),
|
||||
"."
|
||||
]
|
||||
: ["-cz", "-f", archivePath, "-C", cachePath, "."];
|
||||
|
||||
expect(execMock).toHaveBeenCalledTimes(1);
|
||||
expect(execMock).toHaveBeenCalledWith(`"tar"`, args);
|
||||
expect(createTarMock).toHaveBeenCalledTimes(1);
|
||||
expect(createTarMock).toHaveBeenCalledWith(archivePath, cachePath);
|
||||
|
||||
expect(logWarningMock).toHaveBeenCalledTimes(1);
|
||||
expect(logWarningMock).toHaveBeenCalledWith(
|
||||
|
@ -259,7 +240,7 @@ test("save with server error outputs warning", async () => {
|
|||
const cachePath = path.resolve(inputPath);
|
||||
testUtils.setInput(Inputs.Path, inputPath);
|
||||
|
||||
const execMock = jest.spyOn(exec, "exec");
|
||||
const createTarMock = jest.spyOn(tar, "createTar");
|
||||
|
||||
const saveCacheMock = jest
|
||||
.spyOn(cacheHttpClient, "saveCache")
|
||||
|
@ -271,21 +252,8 @@ test("save with server error outputs warning", async () => {
|
|||
|
||||
const archivePath = path.join("/foo/bar", "cache.tgz");
|
||||
|
||||
const IS_WINDOWS = process.platform === "win32";
|
||||
const args = IS_WINDOWS
|
||||
? [
|
||||
"-cz",
|
||||
"--force-local",
|
||||
"-f",
|
||||
archivePath.replace(/\\/g, "/"),
|
||||
"-C",
|
||||
cachePath.replace(/\\/g, "/"),
|
||||
"."
|
||||
]
|
||||
: ["-cz", "-f", archivePath, "-C", cachePath, "."];
|
||||
|
||||
expect(execMock).toHaveBeenCalledTimes(1);
|
||||
expect(execMock).toHaveBeenCalledWith(`"tar"`, args);
|
||||
expect(createTarMock).toHaveBeenCalledTimes(1);
|
||||
expect(createTarMock).toHaveBeenCalledWith(archivePath, cachePath);
|
||||
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(saveCacheMock).toHaveBeenCalledWith(primaryKey, archivePath);
|
||||
|
@ -321,29 +289,15 @@ test("save with valid inputs uploads a cache", async () => {
|
|||
const cachePath = path.resolve(inputPath);
|
||||
testUtils.setInput(Inputs.Path, inputPath);
|
||||
|
||||
const execMock = jest.spyOn(exec, "exec");
|
||||
|
||||
const createTarMock = jest.spyOn(tar, "createTar");
|
||||
const saveCacheMock = jest.spyOn(cacheHttpClient, "saveCache");
|
||||
|
||||
await run();
|
||||
|
||||
const archivePath = path.join("/foo/bar", "cache.tgz");
|
||||
|
||||
const IS_WINDOWS = process.platform === "win32";
|
||||
const args = IS_WINDOWS
|
||||
? [
|
||||
"-cz",
|
||||
"--force-local",
|
||||
"-f",
|
||||
archivePath.replace(/\\/g, "/"),
|
||||
"-C",
|
||||
cachePath.replace(/\\/g, "/"),
|
||||
"."
|
||||
]
|
||||
: ["-cz", "-f", archivePath, "-C", cachePath, "."];
|
||||
|
||||
expect(execMock).toHaveBeenCalledTimes(1);
|
||||
expect(execMock).toHaveBeenCalledWith(`"tar"`, args);
|
||||
expect(createTarMock).toHaveBeenCalledTimes(1);
|
||||
expect(createTarMock).toHaveBeenCalledWith(archivePath, cachePath);
|
||||
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(saveCacheMock).toHaveBeenCalledWith(primaryKey, archivePath);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue