| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { servicePath } from "./registry-paths.ts"; |
| 5 | |
| 6 | test("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 | |
| 20 | test("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 | |
| 38 | test("the Composer registries go to the packages service", () => { |
| 39 | for (const path of [ |
| 40 | "/-/composer/acme/packages.json", |
| 41 | "/-/composer/acme/p2/acme/lib.json", |
| 42 | "/-/composer/acme/p2/acme/lib~dev.json", |
| 43 | `/-/composer/acme/dist/acme/lib/${"a".repeat(40)}.zip`, |
| 44 | ]) { |
| 45 | assert.equal(servicePath(path), "packages", path); |
| 46 | } |
| 47 | assert.equal(servicePath("/-/composer"), null); |
| 48 | }); |
| 49 | |
| 50 | test("git goes to repos, and everything else is the site's", () => { |
| 51 | assert.equal(servicePath("/acme/web.git/info/refs"), "git"); |
| 52 | assert.equal(servicePath("/acme/web/git-receive-pack"), "git"); |
| 53 | // A registry image named like a git endpoint is still the registry's. |
| 54 | assert.equal(servicePath("/v2/acme/info/refs"), "packages"); |
| 55 | for (const path of ["/", "/acme", "/acme/web", "/v2x", "/acme/v2", "/acme/-/packages"]) { |
| 56 | assert.equal(servicePath(path), null, path); |
| 57 | } |
| 58 | }); |