mirror of
https://github.com/actions/cache.git
synced 2025-06-18 23:02:57 -06:00
Fix script invocations, lint and format.
Signed-off-by: Gregorio Litenstein <g.litenstein@gmail.com>
This commit is contained in:
parent
8ac3d1967f
commit
11a6324cc7
8 changed files with 240 additions and 175 deletions
|
@ -1,14 +1,18 @@
|
|||
/* istanbul ignore file */
|
||||
|
||||
import { Inputs } from "../constants";
|
||||
import { rest } from "msw";
|
||||
import { setupServer } from "msw/node";
|
||||
import nock from "nock";
|
||||
|
||||
export const successCacheKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
export const wrongRefCacheKey = "Linux-latest-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
export const failureCacheKey = "Windows-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
export const passThroughCacheKey = "macOS-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
import { Inputs } from "../constants";
|
||||
|
||||
export const successCacheKey =
|
||||
"Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
export const wrongRefCacheKey =
|
||||
"Linux-latest-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
export const failureCacheKey =
|
||||
"Windows-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
export const passThroughCacheKey =
|
||||
"macOS-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
const successCacheId = 1337;
|
||||
const failureCacheId = 69;
|
||||
|
||||
|
@ -61,79 +65,109 @@ export function clearInputs(): void {
|
|||
}
|
||||
|
||||
export const mockServer = setupServer(
|
||||
rest.delete('https://api.github.com/repos/owner/repo/actions/caches/', (req, res, ctx) => {
|
||||
return res(ctx.status(422),
|
||||
ctx.json({
|
||||
message: "Invalid request.\n\nMissing required query parameter key",
|
||||
documentation_url: "https://docs.github.com/rest/actions/cache#delete-github-actions-caches-for-a-repository-using-a-cache-key",
|
||||
})
|
||||
)
|
||||
}),
|
||||
rest.delete('https://api.github.com/repos/owner/repo/actions/caches/:id', (req, res, ctx) => {
|
||||
const { id } = req.params;
|
||||
if (parseInt(id as string) === failureCacheId) {
|
||||
return res(ctx.status(404),
|
||||
rest.delete(
|
||||
"https://api.github.com/repos/owner/repo/actions/caches/",
|
||||
(req, res, ctx) => {
|
||||
return res(
|
||||
ctx.status(422),
|
||||
ctx.json({
|
||||
message: "Not Found",
|
||||
documentation_url: "https://docs.github.com/rest/actions/cache#delete-a-github-actions-cache-for-a-repository-using-a-cache-id"
|
||||
}));
|
||||
message:
|
||||
"Invalid request.\n\nMissing required query parameter key",
|
||||
documentation_url:
|
||||
"https://docs.github.com/rest/actions/cache#delete-github-actions-caches-for-a-repository-using-a-cache-key"
|
||||
})
|
||||
);
|
||||
}
|
||||
return res(ctx.status(204));
|
||||
}),
|
||||
),
|
||||
rest.delete(
|
||||
"https://api.github.com/repos/owner/repo/actions/caches/:id",
|
||||
(req, res, ctx) => {
|
||||
const { id } = req.params;
|
||||
if (parseInt(id as string) === failureCacheId) {
|
||||
return res(
|
||||
ctx.status(404),
|
||||
ctx.json({
|
||||
message: "Not Found",
|
||||
documentation_url:
|
||||
"https://docs.github.com/rest/actions/cache#delete-a-github-actions-cache-for-a-repository-using-a-cache-id"
|
||||
})
|
||||
);
|
||||
}
|
||||
return res(ctx.status(204));
|
||||
}
|
||||
),
|
||||
// This endpoint always returns 200/OK, what we're checking here is whether we can get a unique cache ID, to avoid deleting the wrong entry.
|
||||
rest.get('https://api.github.com/repos/owner/repo/actions/caches', (req, res, ctx) => {
|
||||
let key : string = req.url?.searchParams?.get('key') || '';
|
||||
let ref : string = req.url?.searchParams?.get('ref') || '';
|
||||
if (key === '' || ref === '') {
|
||||
return res(ctx.status(200),
|
||||
ctx.json({
|
||||
total_count: 2,
|
||||
actions_caches: [{
|
||||
id: 15,
|
||||
ref: "refs/heads/main",
|
||||
key: failureCacheKey,
|
||||
version: "73885106f58cc52a7df9ec4d4a5622a5614813162cb516c759a30af6bf56e6f0",
|
||||
last_accessed_at: "2022-12-29T22:06:42.683333300Z",
|
||||
created_at: "2022-12-29T22:06:42.683333300Z",
|
||||
size_in_bytes: 6057793
|
||||
},
|
||||
{
|
||||
id: 16,
|
||||
ref: "refs/heads/another-feature-branch",
|
||||
key: failureCacheKey,
|
||||
version: "73885106f58cc52a7df9ec4d4a5622a5614813162cb516c759a30af6bf56e6f0",
|
||||
last_accessed_at: "2022-12-29T22:06:42.683333300Z",
|
||||
created_at: "2022-12-29T22:06:42.683333300Z",
|
||||
size_in_bytes: 6057793
|
||||
}]
|
||||
})
|
||||
);
|
||||
rest.get(
|
||||
"https://api.github.com/repos/owner/repo/actions/caches",
|
||||
(req, res, ctx) => {
|
||||
const key: string = req.url?.searchParams?.get("key") || "";
|
||||
const ref: string = req.url?.searchParams?.get("ref") || "";
|
||||
if (key === "" || ref === "") {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.json({
|
||||
total_count: 2,
|
||||
actions_caches: [
|
||||
{
|
||||
id: 15,
|
||||
ref: "refs/heads/main",
|
||||
key: failureCacheKey,
|
||||
version:
|
||||
"73885106f58cc52a7df9ec4d4a5622a5614813162cb516c759a30af6bf56e6f0",
|
||||
last_accessed_at:
|
||||
"2022-12-29T22:06:42.683333300Z",
|
||||
created_at: "2022-12-29T22:06:42.683333300Z",
|
||||
size_in_bytes: 6057793
|
||||
},
|
||||
{
|
||||
id: 16,
|
||||
ref: "refs/heads/another-feature-branch",
|
||||
key: failureCacheKey,
|
||||
version:
|
||||
"73885106f58cc52a7df9ec4d4a5622a5614813162cb516c759a30af6bf56e6f0",
|
||||
last_accessed_at:
|
||||
"2022-12-29T22:06:42.683333300Z",
|
||||
created_at: "2022-12-29T22:06:42.683333300Z",
|
||||
size_in_bytes: 6057793
|
||||
}
|
||||
]
|
||||
})
|
||||
);
|
||||
}
|
||||
// This is the behavior seen when search doesn't find anything, but it is seen both when no key matches, as well as when the key matches but the entry belongs to another (likely the base) branch.
|
||||
else if (key === wrongRefCacheKey) {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.json({
|
||||
total_count: 0,
|
||||
actions_caches: []
|
||||
})
|
||||
);
|
||||
} else if (key === successCacheKey || key === failureCacheKey) {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.json({
|
||||
total_count: 1,
|
||||
actions_caches: [
|
||||
{
|
||||
id:
|
||||
key === successCacheKey
|
||||
? successCacheId
|
||||
: failureCacheId,
|
||||
ref: ref,
|
||||
key: key,
|
||||
version:
|
||||
"93a0f912fdb70083e929c1bf564bca2050be1c4e0932f7f9e78465ddcfbcc8f6",
|
||||
last_accessed_at:
|
||||
"2022-12-29T22:06:42.683333300Z",
|
||||
created_at: "2022-12-29T22:06:42.683333300Z",
|
||||
size_in_bytes: 6057793
|
||||
}
|
||||
]
|
||||
})
|
||||
);
|
||||
}
|
||||
return req.passthrough();
|
||||
}
|
||||
// This is the behavior seen when search doesn't find anything, but it is seen both when no key matches, as well as when the key matches but the entry belongs to another (likely the base) branch.
|
||||
else if (key === wrongRefCacheKey) {
|
||||
return res(ctx.status(200),
|
||||
ctx.json({
|
||||
total_count: 0,
|
||||
actions_caches: []
|
||||
})
|
||||
);
|
||||
}
|
||||
else if (key === successCacheKey || key === failureCacheKey) {
|
||||
return res(ctx.status(200),
|
||||
ctx.json({
|
||||
total_count: 1,
|
||||
actions_caches: [{
|
||||
id: (key === successCacheKey ? successCacheId : failureCacheId),
|
||||
ref: ref,
|
||||
key: key,
|
||||
version: "93a0f912fdb70083e929c1bf564bca2050be1c4e0932f7f9e78465ddcfbcc8f6",
|
||||
last_accessed_at: "2022-12-29T22:06:42.683333300Z",
|
||||
created_at: "2022-12-29T22:06:42.683333300Z",
|
||||
size_in_bytes: 6057793
|
||||
}]
|
||||
})
|
||||
);
|
||||
}
|
||||
return req.passthrough();
|
||||
})
|
||||
);
|
||||
)
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue