g1t/apps/web/app/lib/registry-paths.test.ts

46 lines1,515 bytesCodeBlame
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { servicePath } from "./registry-paths.ts";
5
6test("the container registry's paths go to the packages service", () => {
7 for (const path of [
8 "/v2",
9 "/v2/",
10 "/v2/token",
11 "/v2/acme/web/manifests/latest",
12 "/v2/acme/web/api/blobs/uploads/upl_1",
13 "/v2/acme/web/tags/list",
14 "/v2/acme/web/referrers/sha256:abc",
15 ]) {
16 assert.equal(servicePath(path), "packages", path);
17 }
18});
19
20test("the npm registry's paths go to the packages service", () => {
21 for (const path of [
22 "/-/npm",
23 "/-/npm/",
24 "/-/npm/@acme%2fweb",
25 "/-/npm/@acme/web/-/web-1.0.0.tgz",
26 "/-/npm/-/package/@acme%2fweb/dist-tags/next",
27 "/-/npm/-/whoami",
28 // A package named like a git endpoint is still npm's.
29 "/-/npm/@acme/info/refs",
30 ]) {
31 assert.equal(servicePath(path), "packages", path);
32 }
33 for (const path of ["/-/npmx", "/acme/-/npm", "/acme/-/packages"]) {
34 assert.equal(servicePath(path), null, path);
35 }
36});
37
38test("git goes to repos, and everything else is the site's", () => {
39 assert.equal(servicePath("/acme/web.git/info/refs"), "git");
40 assert.equal(servicePath("/acme/web/git-receive-pack"), "git");
41 // A registry image named like a git endpoint is still the registry's.
42 assert.equal(servicePath("/v2/acme/info/refs"), "packages");
43 for (const path of ["/", "/acme", "/acme/web", "/v2x", "/acme/v2", "/acme/-/packages"]) {
44 assert.equal(servicePath(path), null, path);
45 }
46});