Merge pull request #15598 from cpuguy83/15570_fix_exec_tty

Fix issue with exec TTY caused by 15446
This commit is contained in:
Arnaud Porterie
2015-08-14 19:43:04 -07:00
2 changed files with 32 additions and 3 deletions

View File

@@ -42,3 +42,31 @@ func (s *DockerSuite) TestExecInteractiveStdinClose(c *check.C) {
c.Fatal("timed out running docker exec")
}
}
func (s *DockerSuite) TestExecTTY(c *check.C) {
dockerCmd(c, "run", "-d", "--name=test", "busybox", "sh", "-c", "echo hello > /foo && top")
cmd := exec.Command(dockerBinary, "exec", "-it", "test", "sh")
p, err := pty.Start(cmd)
c.Assert(err, check.IsNil)
defer p.Close()
_, err = p.Write([]byte("cat /foo && exit\n"))
c.Assert(err, check.IsNil)
chErr := make(chan error)
go func() {
chErr <- cmd.Wait()
}()
select {
case err := <-chErr:
c.Assert(err, check.IsNil)
case <-time.After(3 * time.Second):
c.Fatal("timeout waiting for exec to exit")
}
buf := make([]byte, 256)
read, err := p.Read(buf)
c.Assert(err, check.IsNil)
c.Assert(bytes.Contains(buf, []byte("hello")), check.Equals, true, check.Commentf(string(buf[:read])))
}