Skip to content

Commit

Permalink
add cli test
Browse files Browse the repository at this point in the history
  • Loading branch information
i2bskn committed Dec 16, 2015
1 parent d9a0dfa commit 7e06017
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,43 @@ func TestRun__versionFlag(t *testing.T) {
cli := &CLI{outStream: outStream, errStream: errStream}
args := strings.Split("github-issues -version", " ")

status := cli.Run(args)
if status != ExitCodeOK {
t.Fatalf("Expected %v, but %v", ExitCodeOK, status)
exitCode := cli.Run(args)
if exitCode != ExitCodeOK {
t.Fatalf("Expected %v, but %v", ExitCodeOK, exitCode)
}

expected := fmt.Sprintf("%s version %s", AppName, Version)
if !strings.Contains(errStream.String(), expected) {
t.Fatalf("Expected %v, but %v", expected, errStream.String())
}
}

func TestRun__helpFlag(t *testing.T) {
outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)
cli := &CLI{outStream: outStream, errStream: errStream}
args := strings.Split("github-issues -help", " ")

exitCode := cli.Run(args)
if exitCode != ExitCodeOK {
t.Fatalf("Expected %v, but %v", ExitCodeOK, exitCode)
}

if !strings.Contains(outStream.String(), usage) {
t.Fatalf("Expected %v, but %v", usage, outStream.String())
}
}

func TestRun__parseError(t *testing.T) {
outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)
cli := &CLI{outStream: outStream, errStream: errStream}
args := strings.Split("github-issues -invalid", " ")

exitCode := cli.Run(args)
if exitCode != ExitCodeFlagParseError {
t.Fatalf("Expected %v, but %v", ExitCodeFlagParseError, exitCode)
}

if !strings.Contains(outStream.String(), usage) {
t.Fatalf("Expected %v, but %v", usage, outStream.String())
}
}

0 comments on commit 7e06017

Please sign in to comment.