e2e/goimport_test.go

419f6dfdc5489a0c6374e36dd1ebbfca68040056
gitbay/e2e/goimport_test.go history · blame · raw

35 lines · 1248 bytes

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