cmd/gitbay/term_test.go

0666c9f622171df00f8e2c79a13d011522039624
gitbay/cmd/gitbay/term_test.go

79 lines · 2144 bytes

 1package main
 2
 3import (
 4	"strings"
 5	"testing"
 6)
 7
 8func TestTermValue(t *testing.T) {
 9	env := func(m map[string]string) func(string) string {
10		return func(k string) string { return m[k] }
11	}
12	cases := []struct {
13		tty     bool
14		cols    int
15		env     map[string]string
16		noColor bool
17		want    string
18	}{
19		{true, 120, nil, false, "120,color"},
20		{false, 120, nil, false, ""},
21		{true, 30, nil, false, ""},
22		{true, 120, map[string]string{"NO_COLOR": "1"}, false, "120"},
23		{true, 120, map[string]string{"TERM": "dumb"}, false, "120"},
24		{true, 120, nil, true, "120"},
25		{true, 120, map[string]string{"GITBAY_TERM": "off"}, false, ""},
26	}
27	for _, c := range cases {
28		noColor = c.noColor
29		if got := termValue(c.tty, c.cols, env(c.env)); got != c.want {
30			t.Errorf("%+v: got %q", c, got)
31		}
32	}
33	noColor = false
34}
35
36func TestStripNoColor(t *testing.T) {
37	args, ok := stripNoColor([]string{"gitbay", "issue", "list", "--no-color", "--state", "all"})
38	if !ok || len(args) != 5 || args[3] != "--state" {
39		t.Errorf("got %v %v", args, ok)
40	}
41}
42
43func TestPagerArgv(t *testing.T) {
44	env := func(m map[string]string) func(string) (string, bool) {
45		return func(k string) (string, bool) { v, ok := m[k]; return v, ok }
46	}
47	cases := []struct {
48		env  map[string]string
49		want string
50	}{
51		{nil, "less"},
52		{map[string]string{"PAGER": "more -s"}, "more -s"},
53		{map[string]string{"PAGER": "more", "GITBAY_PAGER": "bat -p"}, "bat -p"},
54		{map[string]string{"PAGER": "more", "GITBAY_PAGER": ""}, ""},
55	}
56	for _, c := range cases {
57		if got := strings.Join(pagerArgv(env(c.env)), " "); got != c.want {
58			t.Errorf("%v: got %q want %q", c.env, got, c.want)
59		}
60	}
61}
62
63func TestPages(t *testing.T) {
64	yes := [][]string{{"issue", "show"}, {"mr", "diff"}, {"build", "log"}, {"repo", "log"}}
65	for _, s := range yes {
66		if !pages(s, nil) {
67			t.Errorf("%v should page", s)
68		}
69	}
70	if pages([]string{"build", "log"}, []string{"--follow"}) {
71		t.Error("build log --follow must not page")
72	}
73	if pages([]string{"issue", "show"}, []string{"--json"}) {
74		t.Error("--json must not page")
75	}
76	if pages([]string{"issue", "list"}, nil) {
77		t.Error("list must not page")
78	}
79}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form