| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { goImport } from "./go-get.ts"; |
| 5 | |
| 6 | test("go get finds a repository's code from its address and any package in it", () => { |
| 7 | for (const path of ["/acme/lib", "/acme/lib/", "/acme/lib/pkg/sub", "/acme/lib.git"]) { |
| 8 | const page = goImport(new URL(`https://g1t.sh${path}?go-get=1`)); |
| 9 | assert.ok(page, path); |
| 10 | assert.match(page, /<meta name="go-import" content="g1t\.sh\/acme\/lib git https:\/\/g1t\.sh\/acme\/lib\.git">/); |
| 11 | assert.match(page, /<meta name="go-source" content="g1t\.sh\/acme\/lib https:\/\/g1t\.sh\/acme\/lib /); |
| 12 | } |
| 13 | }); |
| 14 | |
| 15 | test("only go-get requests for a repository's address are answered", () => { |
| 16 | assert.equal(goImport(new URL("https://g1t.sh/acme/lib")), null, "no go-get"); |
| 17 | assert.equal(goImport(new URL("https://g1t.sh/acme/lib?go-get=0")), null); |
| 18 | assert.equal(goImport(new URL("https://g1t.sh/acme?go-get=1")), null, "a workspace is not a module"); |
| 19 | assert.equal(goImport(new URL("https://g1t.sh/acme/-/packages?go-get=1")), null, "workspace pages"); |
| 20 | assert.equal(goImport(new URL("https://g1t.sh/Acme/lib?go-get=1")), null); |
| 21 | assert.equal(goImport(new URL("https://g1t.sh/acme/%22%3E?go-get=1")), null, "nothing is put in the page unchecked"); |
| 22 | }); |