forked from yusukebe/revealgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli_test.go
44 lines (37 loc) · 1.03 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
package revealgo
import (
"bytes"
"fmt"
"strings"
"testing"
)
func TestRunFlagExitCode(t *testing.T) {
outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)
cli := CLI{OutStream: outStream, ErrStream: errStream}
flags := []struct {
flag string
expected int
}{
{flag: "version", expected: ExitCodeOK},
{flag: "help", expected: ExitCodeOK},
{flag: "blahblah", expected: ExitCodeError},
}
for _, f := range flags {
command := fmt.Sprintf("revealgo --%s", f.flag)
args := strings.Split(command, " ")
status := cli.Run(args)
if status != f.expected {
t.Errorf("got %v\n want %v", status, f.expected)
}
}
}
func TestRun_versionFlag(t *testing.T) {
outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)
cli := CLI{OutStream: outStream, ErrStream: errStream}
args := strings.Split("revealgo --version", " ")
cli.Run(args)
expected := fmt.Sprintf("revealgo version %s\n", Version)
if !strings.Contains(outStream.String(), expected) {
t.Errorf("Output=%q, want %q", outStream.String(), expected)
}
}