-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli_test.go
38 lines (35 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
package main
import (
"bytes"
"strings"
"testing"
)
func TestCliRun(t *testing.T) {
outStream, errStream := new(bytes.Buffer), new(bytes.Buffer)
cli := &CLI{outStream: outStream, errStream: errStream}
cases := []struct {
name string
input []string
out string
err string
exitCode int
}{
{name: "output is correct", input: []string{"dog dog dog. cat. fish fish. go go go go."}, out: "go\ndog\nfish\n", err: "", exitCode: 0},
{name: "invalid input", input: []string{"bb", "aa"}, out: "", err: "arguments must be single sentence. Your specified 2 arguments", exitCode: 1},
}
for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
actualCode := cli.Run(c.input)
if actualCode != c.exitCode {
t.Errorf("expected %d, but got: %d", c.exitCode, actualCode)
}
if !strings.Contains(outStream.String(), c.out) {
t.Errorf("expected %s, but got: %s", c.out, outStream.String())
}
if !strings.Contains(errStream.String(), c.err) {
t.Errorf("expected %s, but got: %s", c.err, errStream.String())
}
})
}
}