Skip to content

Instantly share code, notes, and snippets.

@hiyosi
Last active July 22, 2017 15:03
Show Gist options
  • Save hiyosi/11ce9020bf26504019dfd62f88fb588e to your computer and use it in GitHub Desktop.
Save hiyosi/11ce9020bf26504019dfd62f88fb588e to your computer and use it in GitHub Desktop.
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