e2e/badge_test.go

v1.38.0
gitbay/e2e/badge_test.go history · blame · raw

35 lines · 1234 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	t.Parallel()
13	inst := startInstance(t)
14	aliceKey := inst.newKey(t, "alice")
15	inst.admin(t, "admin", "user", "create", "alice", "--key", aliceKey+".pub")
16	if _, errOut, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/app"); code != 0 {
17		t.Fatalf("repo create: %s", errOut)
18	}
19
20	status, body := inst.get(t, "/alice/app/badge/build.svg")
21	if status != 200 || !strings.Contains(body, "unknown") || !strings.Contains(body, "<svg") {
22		t.Fatalf("badge before any build: %d\n%s", status, body)
23	}
24
25	// Private repositories have no badge, like every other surface.
26	if _, _, code := inst.ssh(t, aliceKey, "", "repo", "create", "alice/vault", "--private"); code != 0 {
27		t.Fatal("private repo create failed")
28	}
29	if status, _ := inst.get(t, "/alice/vault/badge/build.svg"); status != 404 {
30		t.Fatalf("private badge: %d", status)
31	}
32	if status, _ := inst.get(t, "/alice/nope/badge/build.svg"); status != 404 {
33		t.Fatalf("missing repo badge: %d", status)
34	}
35}