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