pull request feedback

pull/1689/head
StephenHodgson 3 days ago
parent 6018dbe2dc
commit 114dd526d5

@ -197,6 +197,14 @@ test("getCompressionLevel allows zero for no compression", () => {
expect(actionUtils.getCompressionLevel("foo")).toBe(0); 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", () => { test("getCompressionLevel returns undefined and warns if input is too large", () => {
const infoMock = jest.spyOn(core, "info"); const infoMock = jest.spyOn(core, "info");
testUtils.setInput("foo", "11"); testUtils.setInput("foo", "11");
@ -218,7 +226,7 @@ test("setCompressionLevel sets no-compression flag when zero", () => {
expect(process.env["GZIP"]).toBe("-0"); expect(process.env["GZIP"]).toBe("-0");
}); });
test("higher compression level produces smaller gzip output", () => { test("higher compression level produces smaller gzip output", () => {
const data = Buffer.alloc(8 * 1024, "A"); const data = Buffer.alloc(8 * 1024, "A");
const level0 = zlib.gzipSync(data, { level: 0 }); const level0 = zlib.gzipSync(data, { level: 0 });
@ -226,7 +234,7 @@ test("setCompressionLevel sets no-compression flag when zero", () => {
expect(level0.byteLength).toBeGreaterThan(level9.byteLength); expect(level0.byteLength).toBeGreaterThan(level9.byteLength);
expect(level0.byteLength - level9.byteLength).toBeGreaterThan(1000); expect(level0.byteLength - level9.byteLength).toBeGreaterThan(1000);
}); });
test("getInputAsInt throws if required and value missing", () => { test("getInputAsInt throws if required and value missing", () => {
expect(() => expect(() =>

@ -136,3 +136,54 @@ test("save with valid inputs uploads a cache", async () => {
expect(failedMock).toHaveBeenCalledTimes(0); 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 () => { test("save skips setting compression when value is out of range", async () => {
const failedMock = jest.spyOn(core, "setFailed"); const failedMock = jest.spyOn(core, "setFailed");
const setCompressionLevelMock = jest.spyOn(actionUtils, "setCompressionLevel"); const setCompressionLevelMock = jest.spyOn(
actionUtils,
"setCompressionLevel"
);
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43"; const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
const savedCacheKey = "Linux-node-"; const savedCacheKey = "Linux-node-";
@ -518,3 +521,54 @@ test("save skips setting compression when value is out of range", async () => {
expect(failedMock).toHaveBeenCalledTimes(0); 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); 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 () => { test("save failing logs the warning message", async () => {
const warningMock = jest.spyOn(core, "warning"); const warningMock = jest.spyOn(core, "warning");

Loading…
Cancel
Save