-
Notifications
You must be signed in to change notification settings - Fork 4
/
cli_test.go
41 lines (37 loc) · 1.09 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
package main
import (
"bytes"
"strings"
"testing"
)
func TestRun_global(t *testing.T) {
tests := []struct {
desc string
arg string
expectedStatus int
expectedSubOut string
expectedSubErr string
}{
{
desc: "undefined flag",
arg: "lsconntrack --undefined",
expectedStatus: exitCodeFlagParseError,
expectedSubErr: "flag provided but not defined",
},
}
for _, tc := range tests {
outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)
cli := &CLI{outStream: outStream, errStream: errStream}
args := strings.Split(tc.arg, " ")
status := cli.Run(args)
if status != tc.expectedStatus {
t.Errorf("desc: %q, status should be %v, not %v", tc.desc, tc.expectedStatus, status)
}
if !strings.Contains(outStream.String(), tc.expectedSubOut) {
t.Errorf("desc: %q, subout should contain %q, got %q", tc.desc, tc.expectedSubOut, outStream.String())
}
if !strings.Contains(errStream.String(), tc.expectedSubErr) {
t.Errorf("desc: %q, subout should contain %q, got %q", tc.desc, tc.expectedSubErr, errStream.String())
}
}
}