fd3783cc8d
+ added test coverage
115 lines
3.5 KiB
TypeScript
115 lines
3.5 KiB
TypeScript
import { setupServer } from "msw/node";
|
|
import { http, HttpResponse, HttpResponseResolver, PathParams } from "msw";
|
|
|
|
const BASE_URI = "https://hub.docker.com/v2";
|
|
|
|
const handlers = [
|
|
http.get<{ namespace: string; repository: string }>(
|
|
`${BASE_URI}/repositories/:namespace/:repository/tags`,
|
|
({ params }) => {
|
|
const { namespace, repository } = params;
|
|
if (namespace !== "vaultwarden" || repository !== "server") {
|
|
return HttpResponse.json(
|
|
{
|
|
message: "httperror 404: object not found",
|
|
errinfo: {
|
|
namespace,
|
|
repository,
|
|
},
|
|
},
|
|
{ status: 404 }
|
|
);
|
|
}
|
|
return HttpResponse.json({
|
|
count: 66,
|
|
next: "https://hub.docker.com/v2/repositories/vaultwarden/server/tags?ordering=last_updated&page=2&page_size=10",
|
|
previous: null,
|
|
results: [
|
|
createImageDescription(
|
|
"1.30.5-alpine",
|
|
"sha256:6f6ec220ed300e1a11475a91d270985915083512f9fb60c1c25783faaa66eef5"
|
|
),
|
|
createImageDescription(
|
|
"latest-alpine",
|
|
"sha256:6f6ec220ed300e1a11475a91d270985915083512f9fb60c1c25783faaa66eef5"
|
|
),
|
|
createImageDescription(
|
|
"alpine",
|
|
"sha256:6f6ec220ed300e1a11475a91d270985915083512f9fb60c1c25783faaa66eef5"
|
|
),
|
|
createImageDescription(
|
|
"1.30.5",
|
|
"sha256:edb8e2bab9cbca22e555638294db9b3657ffbb6e5d149a29d7ccdb243e3c71e0"
|
|
),
|
|
createImageDescription(
|
|
"latest",
|
|
"sha256:edb8e2bab9cbca22e555638294db9b3657ffbb6e5d149a29d7ccdb243e3c71e0"
|
|
),
|
|
createImageDescription(
|
|
"testing-alpine",
|
|
"sha256:af5021d1a4e5debd1dc16a2bef15993c07f93a0e3c6c4acfd1ffcdaaab71bd0d"
|
|
),
|
|
createImageDescription(
|
|
"testing",
|
|
"sha256:293f0127bc2fe0c59b26fea0ec0b990049a65b4f6f0c9f961e345276aadca3fd"
|
|
),
|
|
createImageDescription(
|
|
"1.30.4-alpine",
|
|
"sha256:743209ed6169e595f9fff2412619d6791002057e211f8725b779777e05066df4"
|
|
),
|
|
createImageDescription(
|
|
"1.30.4",
|
|
"sha256:b906f840f02ea481861cd90a4eafb92752f45afa1927a29406a26256f56271ed"
|
|
),
|
|
createImageDescription(
|
|
"1.30.3-alpine",
|
|
"sha256:153defd78a3ede850445d64d6fca283701d0c25978e513c61688cf63bd47a14a"
|
|
),
|
|
],
|
|
});
|
|
}
|
|
),
|
|
];
|
|
|
|
function createImageDescription(name: string, digest: string) {
|
|
return {
|
|
name,
|
|
digest,
|
|
|
|
// fake data irrelevant for our use case
|
|
creator: 14287463,
|
|
id: 613523756,
|
|
images: [
|
|
{
|
|
architecture: "amd64",
|
|
features: "",
|
|
variant: null,
|
|
digest:
|
|
"sha256:9f4c1ea3601e398656992f738af9f84faf7a6d68299b2deaf049580e5da0d37f",
|
|
os: "linux",
|
|
os_features: "",
|
|
os_version: null,
|
|
size: 31945148,
|
|
status: "active",
|
|
last_pulled: "2024-03-10T08:07:35.84822Z",
|
|
last_pushed: "2024-03-02T18:59:17.437196Z",
|
|
},
|
|
],
|
|
last_updated: "2024-03-02T18:59:28.977584Z",
|
|
last_updater: 14287463,
|
|
last_updater_username: "vaultwardenbot",
|
|
repository: 12325169,
|
|
full_size: 31945148,
|
|
v2: true,
|
|
tag_status: "active",
|
|
tag_last_pulled: "2024-03-10T08:07:35.84822Z",
|
|
tag_last_pushed: "2024-03-02T18:59:28.977584Z",
|
|
media_type: "application/vnd.oci.image.index.v1+json",
|
|
content_type: "image",
|
|
};
|
|
}
|
|
|
|
const server = setupServer(...handlers);
|
|
|
|
export default server;
|