github.com/guilhermebr/docker@v1.4.2-0.20150428121140-67da055cebca/integration-cli/docker_cli_exec_unix_test.go (about) 1 // +build !windows,!test_no_exec 2 3 package main 4 5 import ( 6 "bytes" 7 "io" 8 "os/exec" 9 "strings" 10 "time" 11 12 "github.com/go-check/check" 13 "github.com/kr/pty" 14 ) 15 16 // regression test for #12546 17 func (s *DockerSuite) TestExecInteractiveStdinClose(c *check.C) { 18 out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-itd", "busybox", "/bin/cat")) 19 if err != nil { 20 c.Fatal(err) 21 } 22 contId := strings.TrimSpace(out) 23 24 cmd := exec.Command(dockerBinary, "exec", "-i", contId, "echo", "-n", "hello") 25 p, err := pty.Start(cmd) 26 if err != nil { 27 c.Fatal(err) 28 } 29 30 b := bytes.NewBuffer(nil) 31 go io.Copy(b, p) 32 33 ch := make(chan error) 34 go func() { ch <- cmd.Wait() }() 35 36 select { 37 case err := <-ch: 38 if err != nil { 39 c.Errorf("cmd finished with error %v", err) 40 } 41 if output := b.String(); strings.TrimSpace(output) != "hello" { 42 c.Fatalf("Unexpected output %s", output) 43 } 44 case <-time.After(1 * time.Second): 45 c.Fatal("timed out running docker exec") 46 } 47 }