internal/control/buildscreen_test.go

main
gitbay/internal/control/buildscreen_test.go history · blame · raw

69 lines · 2383 bytes

3 symbols in this file
 1package control
 2
 3import (
 4	"strconv"
 5	"strings"
 6	"testing"
 7
 8	"gitbay.org/gitbay/internal/protocol"
 9	"gitbay.org/gitbay/internal/store"
10)
11
12func TestBuildShowPlainPinned(t *testing.T) {
13	st, repo, uid := newQueueTestRepo(t)
14	id, err := st.CreateBuild(repo.ID, "test", "a136534ff9a136534ff9a136534ff9a136534ff9", "main", `["go vet ./...","go test ./..."]`, "", "", true)
15	if err != nil {
16		t.Fatal(err)
17	}
18	if _, ok, err := st.ClaimBuild([]int64{repo.ID}, false); err != nil || !ok {
19		t.Fatalf("claim: %v %v", ok, err)
20	}
21	if err := st.SetBuildFailure(id, 2, "exit 1"); err != nil {
22		t.Fatal(err)
23	}
24	if err := st.FinishBuild(id, "failure"); err != nil {
25		t.Fatal(err)
26	}
27	b, err := st.BuildByID(id)
28	if err != nil {
29		t.Fatal(err)
30	}
31	c, out, errOut := mrTestCtx(st, store.User{ID: uid, Username: "alice"})
32	if code := Dispatch(c, []string{"build", "show", repo.Path(), strconv.FormatInt(b.Number, 10)}); code != protocol.ExitOK {
33		t.Fatalf("exit %d: %s", code, errOut)
34	}
35	pinPlain(t, "build-show", out.String())
36}
37
38func TestBuildShowScreenFailed(t *testing.T) {
39	c := screenCtx(100, false)
40	d := BuildOut{Number: 83, Job: "daily-pull", Status: "failure", SHA: "355b04066b", Ref: "main",
41		Steps: []string{"setup", "pull", "publish"}, FailedStep: 2, FailedReason: "exit 1", DurationS: 74}
42	s := buildShowScreen(c, store.Repo{OwnerName: "krz", Name: "omaha-metro-blotter"}, d, nil)
43	steps := s.sections[0]
44	if steps.title != "Steps" || steps.n != 3 {
45		t.Fatalf("steps = %+v", steps)
46	}
47	for i, want := range []string{"✓", "✗", "○"} {
48		if g := steps.rows[i].cells[0]; g.s != want {
49			t.Errorf("step %d glyph = %q, want %q", i+1, g.s, want)
50		}
51	}
52	if len(s.actions) != 1 || s.actions[0].argv[1] != "log" {
53		t.Errorf("actions = %+v", s.actions)
54	}
55	out := renderString(c, s)
56	if !strings.Contains(out, "✗  pull     exit 1\n") {
57		t.Errorf("failed step line:\n%s", out)
58	}
59	checkActions(t, s)
60}
61
62func TestBuildShowScreenNamesItsMR(t *testing.T) {
63	c := screenCtx(100, false)
64	d := BuildOut{Number: 1781, Job: "test", Status: "running", SHA: "ee77220399", Ref: "cli-views-1"}
65	out := renderString(c, buildShowScreen(c, store.Repo{OwnerName: "krz", Name: "gitbay"}, d, &store.MR{Number: 552, Title: "screen renderer"}))
66	if !strings.Contains(out, "MR:      !552  screen renderer\n") || !strings.Contains(out, "State:   ◐  running\n") {
67		t.Errorf("render:\n%s", out)
68	}
69}