mirror of
https://github.com/actions/cache.git
synced 2025-12-16 19:18:36 +08:00
pull request feedback
This commit is contained in:
parent
6018dbe2dc
commit
114dd526d5
|
|
@ -197,6 +197,14 @@ test("getCompressionLevel allows zero for no compression", () => {
|
|||
expect(actionUtils.getCompressionLevel("foo")).toBe(0);
|
||||
});
|
||||
|
||||
test("getCompressionLevel returns undefined for negative values", () => {
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
|
||||
testUtils.setInput("foo", "-3");
|
||||
expect(actionUtils.getCompressionLevel("foo")).toBeUndefined();
|
||||
expect(infoMock).not.toHaveBeenCalledWith(expect.stringContaining("compression-level"));
|
||||
});
|
||||
|
||||
test("getCompressionLevel returns undefined and warns if input is too large", () => {
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
testUtils.setInput("foo", "11");
|
||||
|
|
@ -218,15 +226,15 @@ test("setCompressionLevel sets no-compression flag when zero", () => {
|
|||
expect(process.env["GZIP"]).toBe("-0");
|
||||
});
|
||||
|
||||
test("higher compression level produces smaller gzip output", () => {
|
||||
const data = Buffer.alloc(8 * 1024, "A");
|
||||
test("higher compression level produces smaller gzip output", () => {
|
||||
const data = Buffer.alloc(8 * 1024, "A");
|
||||
|
||||
const level0 = zlib.gzipSync(data, { level: 0 });
|
||||
const level9 = zlib.gzipSync(data, { level: 9 });
|
||||
const level0 = zlib.gzipSync(data, { level: 0 });
|
||||
const level9 = zlib.gzipSync(data, { level: 9 });
|
||||
|
||||
expect(level0.byteLength).toBeGreaterThan(level9.byteLength);
|
||||
expect(level0.byteLength - level9.byteLength).toBeGreaterThan(1000);
|
||||
});
|
||||
expect(level0.byteLength).toBeGreaterThan(level9.byteLength);
|
||||
expect(level0.byteLength - level9.byteLength).toBeGreaterThan(1000);
|
||||
});
|
||||
|
||||
test("getInputAsInt throws if required and value missing", () => {
|
||||
expect(() =>
|
||||
|
|
|
|||
|
|
@ -136,3 +136,54 @@ test("save with valid inputs uploads a cache", async () => {
|
|||
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("negative compression level leaves env unset in combined flow", async () => {
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const setCompressionLevelMock = jest.spyOn(
|
||||
actionUtils,
|
||||
"setCompressionLevel"
|
||||
);
|
||||
|
||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
const savedCacheKey = "Linux-node-";
|
||||
|
||||
jest.spyOn(core, "getState")
|
||||
// Cache Entry State
|
||||
.mockImplementationOnce(() => {
|
||||
return primaryKey;
|
||||
})
|
||||
// Cache Key State
|
||||
.mockImplementationOnce(() => {
|
||||
return savedCacheKey;
|
||||
});
|
||||
|
||||
const inputPath = "node_modules";
|
||||
testUtils.setInput(Inputs.Path, inputPath);
|
||||
testUtils.setInput(Inputs.UploadChunkSize, "4000000");
|
||||
testUtils.setInput(Inputs.CompressionLevel, "-5");
|
||||
|
||||
const cacheId = 4;
|
||||
const saveCacheMock = jest
|
||||
.spyOn(cache, "saveCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(cacheId);
|
||||
});
|
||||
|
||||
await saveRun();
|
||||
|
||||
expect(process.env["ZSTD_CLEVEL"]).toBeUndefined();
|
||||
expect(process.env["GZIP"]).toBeUndefined();
|
||||
expect(setCompressionLevelMock).not.toHaveBeenCalled();
|
||||
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(saveCacheMock).toHaveBeenCalledWith(
|
||||
[inputPath],
|
||||
primaryKey,
|
||||
{
|
||||
uploadChunkSize: 4000000
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -473,7 +473,10 @@ test("save applies compression level when provided", async () => {
|
|||
|
||||
test("save skips setting compression when value is out of range", async () => {
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const setCompressionLevelMock = jest.spyOn(actionUtils, "setCompressionLevel");
|
||||
const setCompressionLevelMock = jest.spyOn(
|
||||
actionUtils,
|
||||
"setCompressionLevel"
|
||||
);
|
||||
|
||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
const savedCacheKey = "Linux-node-";
|
||||
|
|
@ -518,3 +521,54 @@ test("save skips setting compression when value is out of range", async () => {
|
|||
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("save skips setting compression when value is negative", async () => {
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
const setCompressionLevelMock = jest.spyOn(
|
||||
actionUtils,
|
||||
"setCompressionLevel"
|
||||
);
|
||||
|
||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
const savedCacheKey = "Linux-node-";
|
||||
|
||||
jest.spyOn(core, "getState")
|
||||
// Cache Entry State
|
||||
.mockImplementationOnce(() => {
|
||||
return savedCacheKey;
|
||||
})
|
||||
// Cache Key State
|
||||
.mockImplementationOnce(() => {
|
||||
return primaryKey;
|
||||
});
|
||||
|
||||
const inputPath = "node_modules";
|
||||
testUtils.setInput(Inputs.Path, inputPath);
|
||||
testUtils.setInput(Inputs.UploadChunkSize, "4000000");
|
||||
testUtils.setInput(Inputs.CompressionLevel, "-1");
|
||||
|
||||
const cacheId = 4;
|
||||
const saveCacheMock = jest
|
||||
.spyOn(cache, "saveCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(cacheId);
|
||||
});
|
||||
|
||||
await saveImpl(new StateProvider());
|
||||
|
||||
expect(process.env["ZSTD_CLEVEL"]).toBeUndefined();
|
||||
expect(process.env["GZIP"]).toBeUndefined();
|
||||
expect(setCompressionLevelMock).not.toHaveBeenCalled();
|
||||
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(saveCacheMock).toHaveBeenCalledWith(
|
||||
[inputPath],
|
||||
primaryKey,
|
||||
{
|
||||
uploadChunkSize: 4000000
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -127,6 +127,42 @@ test("save with valid inputs uploads a cache", async () => {
|
|||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("negative compression level does not set env vars", async () => {
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
|
||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
|
||||
const inputPath = "node_modules";
|
||||
testUtils.setInput(Inputs.Key, primaryKey);
|
||||
testUtils.setInput(Inputs.Path, inputPath);
|
||||
testUtils.setInput(Inputs.UploadChunkSize, "4000000");
|
||||
testUtils.setInput(Inputs.CompressionLevel, "-2");
|
||||
|
||||
const cacheId = 4;
|
||||
const saveCacheMock = jest
|
||||
.spyOn(cache, "saveCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(cacheId);
|
||||
});
|
||||
|
||||
await saveOnlyRun();
|
||||
|
||||
expect(process.env["ZSTD_CLEVEL"]).toBeUndefined();
|
||||
expect(process.env["GZIP"]).toBeUndefined();
|
||||
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(saveCacheMock).toHaveBeenCalledWith(
|
||||
[inputPath],
|
||||
primaryKey,
|
||||
{
|
||||
uploadChunkSize: 4000000
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("save failing logs the warning message", async () => {
|
||||
const warningMock = jest.spyOn(core, "warning");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user