e2e/dashboardbuild_test.go

v1.33.0
gitbay/e2e/dashboardbuild_test.go history · blame · raw

48 lines · 1661 bytes

 1package e2e
 2
 3import (
 4	"strings"
 5	"testing"
 6)
 7
 8// The dashboard reports which build is serving, so the running commit is
 9// visible without reading the journal. It is admin-only: the exact build a
10// host runs narrows down which known issues apply to it.
11func TestDashboardReportsTheServerBuild(t *testing.T) {
12	inst := startInstance(t)
13
14	adminKey := inst.newKey(t, "root")
15	userKey := inst.newKey(t, "plain")
16	inst.admin(t, "admin", "user", "create", "root", "--key", adminKey+".pub", "--admin")
17	inst.admin(t, "admin", "user", "create", "plain", "--key", userKey+".pub")
18
19	out, errOut, code := inst.ssh(t, adminKey, "", "dashboard", "--json")
20	if code != 0 {
21		t.Fatalf("admin dashboard: %s", errOut)
22	}
23	if !strings.Contains(out, `"server":{"commit":"`) {
24		t.Fatalf("admin dashboard did not report the build:\n%s", out)
25	}
26
27	// A non-admin gets the same dashboard without it. omitempty drops the key
28	// entirely rather than reporting an empty string.
29	out, errOut, code = inst.ssh(t, userKey, "", "dashboard", "--json")
30	if code != 0 {
31		t.Fatalf("user dashboard: %s", errOut)
32	}
33	if strings.Contains(out, `"server"`) {
34		t.Fatalf("a non-admin was told the server build:\n%s", out)
35	}
36	if !strings.Contains(out, `"review_queue"`) {
37		t.Fatalf("user dashboard is missing its usual contents:\n%s", out)
38	}
39
40	// Human output carries it too, for the operator who did not ask for JSON.
41	out, errOut, code = inst.ssh(t, adminKey, "", "dashboard")
42	if code != 0 {
43		t.Fatalf("admin dashboard (human): %s", errOut)
44	}
45	if !strings.Contains(out, "server:") || !strings.Contains(out, "build ") {
46		t.Fatalf("human dashboard did not report the build:\n%s", out)
47	}
48}