X Tutup
Skip to content

Commit 0cfa4be

Browse files
committed
Add tests for utilities of PR/issue state format
1 parent 46a632c commit 0cfa4be

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

command/issue_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"testing"
1212

1313
"github.com/cli/cli/utils"
14+
"github.com/google/go-cmp/cmp"
1415
)
1516

1617
func TestIssueStatus(t *testing.T) {
@@ -585,3 +586,24 @@ func TestIssueCreate_webTitleBody(t *testing.T) {
585586
eq(t, url, "https://github.com/OWNER/REPO/issues/new?title=mytitle&body=mybody")
586587
eq(t, output.String(), "Opening github.com/OWNER/REPO/issues/new in your browser.\n")
587588
}
589+
590+
func TestIssueStateTitleWithColor(t *testing.T) {
591+
tests := map[string]struct {
592+
state string
593+
want string
594+
}{
595+
596+
"Open state": {state: "OPEN", want: "Open"},
597+
"Closed state": {state: "CLOSED", want: "Closed"},
598+
}
599+
600+
for name, tc := range tests {
601+
t.Run(name, func(t *testing.T) {
602+
got := issueStateTitleWithColor(tc.state)
603+
diff := cmp.Diff(tc.want, got)
604+
if diff != "" {
605+
t.Fatalf(diff)
606+
}
607+
})
608+
}
609+
}

command/pr.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,8 @@ func prStateTitleWithColor(pr api.PullRequest) string {
236236
func colorFuncForPR(pr api.PullRequest) func(string) string {
237237
if pr.State == "OPEN" && pr.IsDraft {
238238
return utils.Gray
239-
} else {
240-
return utils.ColorFuncForState(pr.State)
241239
}
240+
return utils.ColorFuncForState(pr.State)
242241
}
243242

244243
func prView(cmd *cobra.Command, args []string) error {

command/pr_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"testing"
1313

1414
"github.com/cli/cli/utils"
15+
"github.com/google/go-cmp/cmp"
1516
"github.com/google/shlex"
1617
"github.com/spf13/cobra"
1718
"github.com/spf13/pflag"
@@ -780,3 +781,25 @@ func TestReplaceExcessiveWhitespace(t *testing.T) {
780781
eq(t, replaceExcessiveWhitespace("hello goodbye"), "hello goodbye")
781782
eq(t, replaceExcessiveWhitespace(" hello \n goodbye "), "hello goodbye")
782783
}
784+
785+
func TestPrStateTitleWithColor(t *testing.T) {
786+
tests := map[string]struct {
787+
state string
788+
want string
789+
}{
790+
791+
"Format OPEN state": {state: "OPEN", want: "Open"},
792+
"Format CLOSED state": {state: "CLOSED", want: "Closed"},
793+
"Format MERGED state": {state: "MERGED", want: "Merged"},
794+
}
795+
796+
for name, tc := range tests {
797+
t.Run(name, func(t *testing.T) {
798+
got := issueStateTitleWithColor(tc.state)
799+
diff := cmp.Diff(tc.want, got)
800+
if diff != "" {
801+
t.Fatalf(diff)
802+
}
803+
})
804+
}
805+
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/briandowns/spinner v1.9.0
88
github.com/charmbracelet/glamour v0.1.1-0.20200304134224-7e5c90143acc
99
github.com/dlclark/regexp2 v1.2.0 // indirect
10+
github.com/google/go-cmp v0.2.0
1011
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
1112
github.com/hashicorp/go-version v1.2.0
1213
github.com/henvic/httpretty v0.0.4

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb
6060
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
6161
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
6262
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
63+
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
6364
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
6465
github.com/google/goterm v0.0.0-20190703233501-fc88cf888a3f h1:5CjVwnuUcp5adK4gmY6i72gpVFVnZDP2h5TmPScB6u4=
6566
github.com/google/goterm v0.0.0-20190703233501-fc88cf888a3f/go.mod h1:nOFQdrUlIlx6M6ODdSpBj1NVA+VgLC6kmw60mkw34H4=

0 commit comments

Comments
 (0)
X Tutup