mirror of
https://code.forgejo.org/actions/cache.git
synced 2026-03-22 07:25:55 +03:00
add compression-level inputs
This commit is contained in:
parent
9255dc7a25
commit
6018dbe2dc
15 changed files with 916 additions and 583 deletions
|
|
@ -40,6 +40,22 @@ beforeAll(() => {
|
|||
}
|
||||
);
|
||||
|
||||
jest.spyOn(actionUtils, "getCompressionLevel").mockImplementation(
|
||||
(name, options) => {
|
||||
return jest
|
||||
.requireActual("../src/utils/actionUtils")
|
||||
.getCompressionLevel(name, options);
|
||||
}
|
||||
);
|
||||
|
||||
jest.spyOn(actionUtils, "setCompressionLevel").mockImplementation(
|
||||
compressionLevel => {
|
||||
return jest
|
||||
.requireActual("../src/utils/actionUtils")
|
||||
.setCompressionLevel(compressionLevel);
|
||||
}
|
||||
);
|
||||
|
||||
jest.spyOn(actionUtils, "isExactKeyMatch").mockImplementation(
|
||||
(key, cacheResult) => {
|
||||
return jest
|
||||
|
|
@ -69,6 +85,8 @@ afterEach(() => {
|
|||
testUtils.clearInputs();
|
||||
delete process.env[Events.Key];
|
||||
delete process.env[RefKey];
|
||||
delete process.env["ZSTD_CLEVEL"];
|
||||
delete process.env["GZIP"];
|
||||
});
|
||||
|
||||
test("save with invalid event outputs warning", async () => {
|
||||
|
|
@ -406,3 +424,97 @@ test("save with valid inputs uploads a cache", async () => {
|
|||
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("save applies compression level when provided", async () => {
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
|
||||
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, "9");
|
||||
|
||||
const cacheId = 4;
|
||||
const saveCacheMock = jest
|
||||
.spyOn(cache, "saveCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(cacheId);
|
||||
});
|
||||
|
||||
await saveImpl(new StateProvider());
|
||||
|
||||
expect(process.env["ZSTD_CLEVEL"]).toBe("9");
|
||||
expect(process.env["GZIP"]).toBe("-9");
|
||||
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(saveCacheMock).toHaveBeenCalledWith(
|
||||
[inputPath],
|
||||
primaryKey,
|
||||
{
|
||||
uploadChunkSize: 4000000
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
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 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, "99");
|
||||
|
||||
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);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue