docker_cli_login_test.go 843 B

1234567891011121314151617181920212223242526272829303132333435
  1. package main
  2. import (
  3. "bytes"
  4. "io"
  5. "os"
  6. "os/exec"
  7. "testing"
  8. )
  9. func TestLoginWithoutTTY(t *testing.T) {
  10. cmd := exec.Command(dockerBinary, "login")
  11. // setup STDOUT and STDERR so that we see any output and errors in our console
  12. cmd.Stdout = os.Stdout
  13. cmd.Stderr = os.Stderr
  14. // create a buffer with text then a new line as a return
  15. buf := bytes.NewBuffer([]byte("buffer test string \n"))
  16. // use a pipe for stdin and manually copy the data so that
  17. // the process does not get the TTY
  18. in, err := cmd.StdinPipe()
  19. if err != nil {
  20. t.Fatal(err)
  21. }
  22. // copy the bytes into the commands stdin along with a new line
  23. go io.Copy(in, buf)
  24. // run the command and block until it's done
  25. if err := cmd.Run(); err == nil {
  26. t.Fatal("Expected non nil err when loginning in & TTY not available")
  27. }
  28. logDone("login - login without TTY")
  29. }