Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement