mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
reuse same code for setting pipes in run/exec
This also moves `exec -i` test to _unix_test.go because it seems to need a pty to reliably reproduce the behavior. Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com>
This commit is contained in:
parent
3c9ae03a86
commit
ade8146aa8
4 changed files with 87 additions and 91 deletions
47
integration-cli/docker_cli_exec_unix_test.go
Normal file
47
integration-cli/docker_cli_exec_unix_test.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
// +build !windows,!test_no_exec
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-check/check"
|
||||
"github.com/kr/pty"
|
||||
)
|
||||
|
||||
// regression test for #12546
|
||||
func (s *DockerSuite) TestExecInteractiveStdinClose(c *check.C) {
|
||||
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-itd", "busybox", "/bin/cat"))
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
contId := strings.TrimSpace(out)
|
||||
|
||||
cmd := exec.Command(dockerBinary, "exec", "-i", contId, "echo", "-n", "hello")
|
||||
p, err := pty.Start(cmd)
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
b := bytes.NewBuffer(nil)
|
||||
go io.Copy(b, p)
|
||||
|
||||
ch := make(chan error)
|
||||
go func() { ch <- cmd.Wait() }()
|
||||
|
||||
select {
|
||||
case err := <-ch:
|
||||
if err != nil {
|
||||
c.Errorf("cmd finished with error %v", err)
|
||||
}
|
||||
if output := b.String(); strings.TrimSpace(output) != "hello" {
|
||||
c.Fatalf("Unexpected output %s", output)
|
||||
}
|
||||
case <-time.After(1 * time.Second):
|
||||
c.Fatal("timed out running docker exec")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue