e2e/badge_test.go
34 lines · 1220 bytes
1package e2e
2
3import (
4 "strings"
5 "testing"
6)
7
8// TestBuildBadge covers the badge endpoint: it reports the newest build,
9// says "unknown" before any build exists, and 404s for a private repo so
10// it cannot be used to probe for one.
11func TestBuildBadge(t *testing.T) {
12 inst := startInstance(t)
13 aliceKey := inst.newKey(t, "alice")
14 inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub")
15 if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 {
16 t.Fatalf("repo create: %s", errOut)
17 }
18
19 status, body := inst.get(t, "/alice/app/badge/build.svg")
20 if status != 200 || !strings.Contains(body, "unknown") || !strings.Contains(body, "<svg") {
21 t.Fatalf("badge before any build: %d\n%s", status, body)
22 }
23
24 // Private repositories have no badge, like every other surface.
25 if _, _, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/vault", "--private"); code != 0 {
26 t.Fatal("private repo create failed")
27 }
28 if status, _ := inst.get(t, "/alice/vault/badge/build.svg"); status != 404 {
29 t.Fatalf("private badge: %d", status)
30 }
31 if status, _ := inst.get(t, "/alice/nope/badge/build.svg"); status != 404 {
32 t.Fatalf("missing repo badge: %d", status)
33 }
34}