e2e/goimport_test.go
34 lines · 1234 bytes
1package e2e
2
3import (
4 "strings"
5 "testing"
6)
7
8func TestGoImportVanity(t *testing.T) {
9 inst := startInstanceWith(t, "[go_import]\n\"127.0.0.1/tool\" = \"alice/tool\"\n")
10 aliceKey := inst.newKey(t, "alice")
11 inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub")
12 if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/tool"); code != 0 {
13 t.Fatalf("repo create: %s", errOut)
14 }
15
16 want := `<meta name="go-import" content="127.0.0.1/tool git https://gitbay.test/alice/tool.git">`
17 status, body := inst.get(t, "/tool?go-get=1")
18 if status != 200 || !strings.Contains(body, want) {
19 t.Fatalf("module root: %d\n%s", status, body)
20 }
21 // Subpackages resolve to the same module.
22 status, body = inst.get(t, "/tool/cmd/x?go-get=1")
23 if status != 200 || !strings.Contains(body, want) {
24 t.Fatalf("subpackage: %d\n%s", status, body)
25 }
26 // Prefix boundary: /toolbox is not under the module.
27 if _, body = inst.get(t, "/toolbox?go-get=1"); strings.Contains(body, "go-import") {
28 t.Fatal("prefix leak: /toolbox matched")
29 }
30 // Without go-get the path routes normally (no owner "tool" -> 404).
31 if status, _ = inst.get(t, "/tool"); status != 404 {
32 t.Fatalf("normal routing broken: %d", status)
33 }
34}