mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
668e2369cc
Addresses: #14603 integration-cli/docker_cli_daemon_experimental_test.go (hqhq) integration-cli/docker_cli_daemon_test.go (hqhq) integration-cli/docker_cli_diff_test.go (hqhq) integration-cli/docker_cli_events_test.go (hqhq) integration-cli/docker_cli_events_unix_test.go (hqhq) integration-cli/docker_cli_exec_test.go (hqhq) integration-cli/docker_cli_exec_unix_test.go (hqhq) integration-cli/docker_cli_experimental_test.go (hqhq) integration-cli/docker_cli_export_import_test.go (hqhq) integration-cli/docker_cli_help_test.go (hqhq) integration-cli/docker_cli_history_test.go (hqhq) integration-cli/docker_cli_images_test.go (hqhq) integration-cli/docker_cli_import_test.go (hqhq) integration-cli/docker_cli_info_test.go (hqhq) integration-cli/docker_cli_inspect_test.go (hqhq) integration-cli/docker_cli_kill_test.go (hqhq) Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
44 lines
893 B
Go
44 lines
893 B
Go
// +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, _ := dockerCmd(c, "run", "-itd", "busybox", "/bin/cat")
|
|
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")
|
|
}
|
|
}
|