-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli_test.go
97 lines (80 loc) · 2.27 KB
/
cli_test.go
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
92
93
94
95
96
97
package main
import (
"bytes"
"fmt"
"strings"
"testing"
)
func TestRun__versionFlag(t *testing.T) {
outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)
cli := &CLI{outStream: outStream, errStream: errStream}
args := strings.Split("gch --version", " ")
status := cli.Run(args)
if status != ExitCodeOK {
t.Errorf("expected %d to eq %d", status, ExitCodeOK)
}
expected := fmt.Sprintf("%s v%s", Name, Version)
if !strings.Contains(errStream.String(), expected) {
t.Errorf("expected %q to eq %q", errStream.String(), expected)
}
}
func TestRun_parseError(t *testing.T) {
outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)
cli := &CLI{outStream: outStream, errStream: errStream}
args := strings.Split("gch --unknown-flag", " ")
status := cli.Run(args)
if status != ExitCodeErrorParseFlag {
t.Errorf("expected %d to eq %d", status, ExitCodeErrorParseFlag)
}
expected := "flag provided but not defined: -unknown-flag"
if !strings.Contains(errStream.String(), expected) {
t.Fatalf("expected %q to contain %q", errStream.String(), expected)
}
}
/*
func TestRunTomlNotFound(t *testing.T) {
outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)
cli := &CLI{outStream: outStream, errStream: errStream}
args := []string{}
status := cli.Run(args)
if status != ExitCodeTomlNotFound {
t.Errorf("expected %d to eq %d", status, ExitCodeTomlNotFound)
}
}
func TestRunTomlParseError(t *testing.T) {
outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)
cli := &CLI{outStream: outStream, errStream: errStream}
f, _ := ioutil.TempFile("", "invalidToml")
content := []byte(`repos = [
github.com/BurntSushi/toml,
]
`)
f.Write(content)
args := []string{
f.Name(),
}
actual := cli.Run(args)
expected := ExitCodeTomlParseError
if actual != expected {
t.Errorf("got %v\nwant %v", actual, expected)
}
}
func TestRunExitCodeOK(t *testing.T) {
outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)
cli := &CLI{outStream: outStream, errStream: errStream}
f, _ := ioutil.TempFile("", "validToml")
content := []byte(`repos = [
"github.com/BurntSushi/toml",
]
`)
f.Write(content)
args := []string{
f.Name(),
}
actual := cli.Run(args)
expected := ExitCodeOK
if actual != expected {
t.Errorf("got %v\nwant %v", actual, expected)
}
}
*/