-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain_test.go
74 lines (60 loc) · 2.02 KB
/
main_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
package main
import (
"bytes"
"fmt"
"strings"
"testing"
"github.com/yuuki/shawk/version"
)
func TestRun_version(t *testing.T) {
outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)
cli := &CLI{outStream: outStream, errStream: errStream}
args := strings.Split("shawk version", " ")
status := cli.Run(args)
if status != 0 {
t.Errorf("expected %d to eq %d", status, exitCodeOK)
}
expected := fmt.Sprintf("shawk version %s", version.GetVersion())
if !strings.Contains(errStream.String(), expected) {
t.Errorf("expected %q to contain %q", expected, errStream.String())
}
}
func TestRun_parseError(t *testing.T) {
outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)
cli := &CLI{outStream: outStream, errStream: errStream}
args := strings.Split("shawk --nonexistent", " ")
status := cli.Run(args)
if status != exitCodeErr {
t.Errorf("expected %d to eq %d", status, exitCodeErr)
}
expected := "Usage: shawk"
if !strings.Contains(errStream.String(), expected) {
t.Errorf("expected %q to contain %q", expected, errStream.String())
}
}
func TestRun_noCommandError(t *testing.T) {
outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)
cli := &CLI{outStream: outStream, errStream: errStream}
args := strings.Split("shawk nonexistent", " ")
status := cli.Run(args)
if status != exitCodeErr {
t.Errorf("expected %d to eq %d", status, exitCodeErr)
}
expected := "No such sub command"
if !strings.Contains(errStream.String(), expected) {
t.Errorf("expected %q to contain %q", expected, errStream.String())
}
}
func TestRun_lookError(t *testing.T) {
outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)
cli := &CLI{outStream: outStream, errStream: errStream}
args := strings.Split("shawk look --depth 100", " ")
status := cli.Run(args)
if status != exitCodeErr {
t.Errorf("expected %d to eq %d", status, exitCodeErr)
}
expected := "depth must be 0 < depth"
if !strings.Contains(errStream.String(), expected) {
t.Errorf("expected %q to contain %q", expected, errStream.String())
}
}