Repository navigation
Expand file tree
/
Copy pathcli_test.go
More file actions
91 lines (84 loc) · 3.21 KB
/
Copy pathcli_test.go
File metadata and controls
91 lines (84 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"errors"
"io"
"testing"
"github.com/RagedPanda/gh-claimcheck/internal/check"
"github.com/RagedPanda/gh-claimcheck/internal/render"
)
func TestParseCheckAllowsFlagsAnywhere(t *testing.T) {
config, err := parseCheck([]string{"12", "--brief", "-R", "acme/lib", "acme/lib#3", "--exit-status"}, io.Discard)
if err != nil {
t.Fatal(err)
}
if len(config.issues) != 2 || config.issues[1] != "acme/lib#3" || config.repo != "acme/lib" || !config.brief || !config.exitStatus {
t.Errorf("config = %+v", config)
}
}
func TestParseCheckHelp(t *testing.T) {
for _, args := range [][]string{{}, {"--help"}, {"-h"}} {
if _, err := parseCheck(args, io.Discard); !errors.Is(err, errHelp) {
t.Errorf("parseCheck(%v) error = %v, want errHelp", args, err)
}
}
if _, err := parseCheck([]string{"--nope"}, io.Discard); err == nil || errors.Is(err, errHelp) {
t.Errorf("unknown flag error = %v", err)
}
}
func TestParseFind(t *testing.T) {
config, err := parseFind([]string{"timezone", "--org", "unjs,vitejs", "--lang", "go", "--good-first-issue", "--go-only", "-s", "500", "parser"}, io.Discard)
if err != nil {
t.Fatal(err)
}
options := config.options
if options.Terms != "timezone parser" || len(options.Orgs) != 2 || options.Languages[0] != "go" || !options.GoodFirstIssue {
t.Errorf("options = %+v", options)
}
if !config.check || config.minStars != 500 || config.limit != 20 || options.Days != 60 || options.MaxComments != 3 {
t.Errorf("config = %+v (--go-only should imply --check; defaults 20/60/3)", config)
}
if _, err := parseFind([]string{"--limit", "0"}, io.Discard); err == nil {
t.Error("--limit 0 should be rejected")
}
}
func TestParseDeps(t *testing.T) {
config, err := parseDeps([]string{"--no-dev", "../app", "--good-first-issue", "--direct-only", "-L", "5", "--list"}, io.Discard)
if err != nil {
t.Fatal(err)
}
if config.dir != "../app" || !config.filter.NoDev || !config.filter.DirectOnly || !config.list {
t.Errorf("config = %+v", config)
}
if !config.find.options.GoodFirstIssue || config.find.limit != 5 || config.find.options.Days != 60 {
t.Errorf("shared flags = %+v", config.find)
}
if defaults, _ := parseDeps(nil, io.Discard); defaults.dir != "." {
t.Errorf("default dir = %q, want .", defaults.dir)
}
if _, err := parseDeps([]string{"a", "b"}, io.Discard); err == nil {
t.Error("two directories should be rejected")
}
if _, err := parseDeps([]string{"--repo", "acme/lib"}, io.Discard); err == nil {
t.Error("--repo is a find flag and should be rejected by deps")
}
if _, err := parseDeps([]string{"--help"}, io.Discard); !errors.Is(err, errHelp) {
t.Errorf("--help error = %v", err)
}
}
func TestExitCode(t *testing.T) {
result := func(verdict string) render.Result { return render.Result{Report: check.Report{Verdict: verdict}} }
cases := []struct {
results []render.Result
want int
}{
{[]render.Result{result(check.Go)}, 0},
{[]render.Result{result(check.Go), result(check.Caution)}, 3},
{[]render.Result{result(check.Caution), result(check.Skip)}, 2},
{[]render.Result{result(check.Skip), {Err: errors.New("x")}}, 1},
}
for _, tc := range cases {
if got := exitCode(tc.results); got != tc.want {
t.Errorf("exitCode = %d, want %d", got, tc.want)
}
}
}