Merge pull request #17162 from echo33/docker_cli_exec_unix_test

use of checkers on docker_cli_exec_unix_test.go
This commit is contained in:
Vincent Demeester 2015-10-19 08:54:42 +02:00
commit cfdb954303

View file

@ -9,6 +9,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check" "github.com/go-check/check"
"github.com/kr/pty" "github.com/kr/pty"
) )
@ -21,9 +22,7 @@ func (s *DockerSuite) TestExecInteractiveStdinClose(c *check.C) {
cmd := exec.Command(dockerBinary, "exec", "-i", contID, "echo", "-n", "hello") cmd := exec.Command(dockerBinary, "exec", "-i", contID, "echo", "-n", "hello")
p, err := pty.Start(cmd) p, err := pty.Start(cmd)
if err != nil { c.Assert(err, checker.IsNil)
c.Fatal(err)
}
b := bytes.NewBuffer(nil) b := bytes.NewBuffer(nil)
go io.Copy(b, p) go io.Copy(b, p)
@ -33,12 +32,9 @@ func (s *DockerSuite) TestExecInteractiveStdinClose(c *check.C) {
select { select {
case err := <-ch: case err := <-ch:
if err != nil { c.Assert(err, checker.IsNil)
c.Errorf("cmd finished with error %v", err) output := b.String()
} c.Assert(strings.TrimSpace(output), checker.Equals, "hello")
if output := b.String(); strings.TrimSpace(output) != "hello" {
c.Fatalf("Unexpected output %s", output)
}
case <-time.After(1 * time.Second): case <-time.After(1 * time.Second):
c.Fatal("timed out running docker exec") c.Fatal("timed out running docker exec")
} }
@ -50,11 +46,11 @@ func (s *DockerSuite) TestExecTTY(c *check.C) {
cmd := exec.Command(dockerBinary, "exec", "-it", "test", "sh") cmd := exec.Command(dockerBinary, "exec", "-it", "test", "sh")
p, err := pty.Start(cmd) p, err := pty.Start(cmd)
c.Assert(err, check.IsNil) c.Assert(err, checker.IsNil)
defer p.Close() defer p.Close()
_, err = p.Write([]byte("cat /foo && exit\n")) _, err = p.Write([]byte("cat /foo && exit\n"))
c.Assert(err, check.IsNil) c.Assert(err, checker.IsNil)
chErr := make(chan error) chErr := make(chan error)
go func() { go func() {
@ -62,13 +58,13 @@ func (s *DockerSuite) TestExecTTY(c *check.C) {
}() }()
select { select {
case err := <-chErr: case err := <-chErr:
c.Assert(err, check.IsNil) c.Assert(err, checker.IsNil)
case <-time.After(3 * time.Second): case <-time.After(3 * time.Second):
c.Fatal("timeout waiting for exec to exit") c.Fatal("timeout waiting for exec to exit")
} }
buf := make([]byte, 256) buf := make([]byte, 256)
read, err := p.Read(buf) read, err := p.Read(buf)
c.Assert(err, check.IsNil) c.Assert(err, checker.IsNil)
c.Assert(bytes.Contains(buf, []byte("hello")), check.Equals, true, check.Commentf(string(buf[:read]))) c.Assert(bytes.Contains(buf, []byte("hello")), checker.Equals, true, check.Commentf(string(buf[:read])))
} }