github.com/stchris/docker@v1.4.2-0.20150106053530-1510a324dbd5/integration-cli/docker_cli_login_test.go (about)

     1  package main
     2  
     3  import (
     4  	"bytes"
     5  	"io"
     6  	"os/exec"
     7  	"testing"
     8  )
     9  
    10  func TestLoginWithoutTTY(t *testing.T) {
    11  	cmd := exec.Command(dockerBinary, "login")
    12  
    13  	// create a buffer with text then a new line as a return
    14  	buf := bytes.NewBuffer([]byte("buffer test string \n"))
    15  
    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  
    25  	// run the command and block until it's done
    26  	if err := cmd.Run(); err == nil {
    27  		t.Fatal("Expected non nil err when loginning in & TTY not available")
    28  	}
    29  
    30  	logDone("login - login without TTY")
    31  }