internal/control/difflayout_test.go

v1.43.0
gitbay/internal/control/difflayout_test.go history · blame · raw

36 lines · 1173 bytes

 1package control
 2
 3import (
 4	"bytes"
 5	"io"
 6	"strings"
 7	"testing"
 8
 9	"gitbay.org/gitbay/internal/protocol"
10	"gitbay.org/gitbay/internal/store"
11)
12
13// web diff show reports unified for a new account, set refuses anything
14// but the two layouts, and a set value is what show reports next.
15func TestWebDiffLayout(t *testing.T) {
16	st, _, uid := newQueueTestRepo(t)
17	var buf bytes.Buffer
18	c := &Ctx{User: store.User{ID: uid, Username: "alice"}, Store: st, Stdout: &buf, Stderr: io.Discard, JSON: true}
19
20	if code := runWebDiffShow(c, nil); code != protocol.ExitOK || !strings.Contains(buf.String(), `"layout":"unified"`) {
21		t.Fatalf("show: %d %s", code, buf.String())
22	}
23	if code := runWebDiffSet(c, []string{"triple"}); code != protocol.ExitUsage {
24		t.Fatalf("bad value exited %d", code)
25	}
26	if code := runWebDiffSet(c, nil); code != protocol.ExitUsage {
27		t.Fatalf("no value exited %d", code)
28	}
29	buf.Reset()
30	if code := runWebDiffSet(c, []string{"split"}); code != protocol.ExitOK || !strings.Contains(buf.String(), `"layout":"split"`) {
31		t.Fatalf("set: %d %s", code, buf.String())
32	}
33	if got, _ := st.DiffLayout(uid); got != "split" {
34		t.Fatalf("stored layout: %q", got)
35	}
36}