Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. package cmd
  2.  
  3. import (
  4. "bytes"
  5. "testing"
  6. )
  7.  
  8. func TestCmd(t *testing.T) {
  9. buf := bytes.NewBuffer([]byte{})
  10. errBuf := bytes.NewBuffer([]byte{})
  11.  
  12. cmd := NewCommandSample(buf, errBuf)
  13. cmd.SetOutput(buf)
  14. cmd.Run(cmd, []string{"hiyosi"})
  15.  
  16. if len(errBuf.String()) != 0 {
  17. t.Errorf("Unexpected output: %v", errBuf.String())
  18. }
  19. if len(buf.String()) == 0 {
  20. t.Error("Unexpected empty output")
  21. }
  22. }
  23.  
  24. func TestCmdWithNoArgs(t *testing.T) {
  25. buf := bytes.NewBuffer([]byte{})
  26. errBuf := bytes.NewBuffer([]byte{})
  27.  
  28. cmd := NewCommandSample(buf, errBuf)
  29. cmd.SetOutput(buf)
  30. cmd.Run(cmd, []string{})
  31.  
  32. if len(errBuf.String()) == 0 {
  33. t.Error("Unexpected empty output")
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement