Skip to content

Commit

Permalink
Add test for sum command
Browse files Browse the repository at this point in the history
  • Loading branch information
mpppk committed Jul 28, 2019
1 parent 9399658 commit 391f94c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions cmd/sum_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cmd

import (
"bytes"
"strings"
"testing"
)

func TestSum(t *testing.T) {
cases := []struct {
command string
want string
}{
{command: "sum -- -1 2", want: "1\n"},
{command: "sum --norm -- -1 2", want: "3\n"},
}

for _, c := range cases {
buf := new(bytes.Buffer)
cmd, err := NewRootCmd()
if err != nil {
t.Errorf("failed to create root cmd: %s", err)
}
cmd.SetOut(buf)
cmdArgs := strings.Split(c.command, " ")
cmd.SetArgs(cmdArgs)
if err := cmd.Execute(); err != nil {
t.Errorf("failed to execute cmd: %s", err)
}

get := buf.String()
if c.want != get {
t.Errorf("unexpected response: want:%q, get:%q", c.want, get)
}
}
}

0 comments on commit 391f94c

Please sign in to comment.