-
Notifications
You must be signed in to change notification settings - Fork 4
/
main_test.go
40 lines (33 loc) · 1022 Bytes
/
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
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("capze --version", " ")
status := cli.Run(args)
if status != 0 {
t.Errorf("expected %d to eq %d", status, 0)
}
expected := fmt.Sprintf("capze version %s", 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("capze --not-exist", " ")
status := cli.Run(args)
if status != 10 {
t.Errorf("expected %d to eq %d", status, 10)
}
expected := "flag provided but not defined"
if !strings.Contains(errStream.String(), expected) {
t.Fatalf("expected %q to contain %q", errStream.String(), expected)
}
}