Last active
July 22, 2017 15:03
-
-
Save hiyosi/11ce9020bf26504019dfd62f88fb588e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cmd | |
import ( | |
"bytes" | |
"testing" | |
) | |
func TestCmd(t *testing.T) { | |
buf := bytes.NewBuffer([]byte{}) | |
errBuf := bytes.NewBuffer([]byte{}) | |
cmd := NewCommandSample(buf, errBuf) | |
cmd.SetOutput(buf) | |
cmd.Run(cmd, []string{"hiyosi"}) | |
if len(errBuf.String()) != 0 { | |
t.Errorf("Unexpected output: %v", errBuf.String()) | |
} | |
if len(buf.String()) == 0 { | |
t.Error("Unexpected empty output") | |
} | |
} | |
func TestCmdWithNoArgs(t *testing.T) { | |
buf := bytes.NewBuffer([]byte{}) | |
errBuf := bytes.NewBuffer([]byte{}) | |
cmd := NewCommandSample(buf, errBuf) | |
cmd.SetOutput(buf) | |
cmd.Run(cmd, []string{}) | |
if len(errBuf.String()) == 0 { | |
t.Error("Unexpected empty output") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment