docker_cli_login_test.go 709 B

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