mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
refactor integration test to use checkers
Signed-off-by: Shijiang Wei <mountkin@gmail.com>
This commit is contained in:
parent
9a13c2dc79
commit
a1d4b7dd0d
2 changed files with 32 additions and 91 deletions
|
@ -22,9 +22,8 @@ func (s *DockerSuite) TestAttachMultipleAndRestart(c *check.C) {
|
|||
endGroup.Add(3)
|
||||
startGroup.Add(3)
|
||||
|
||||
if err := waitForContainer("attacher", "-d", "busybox", "/bin/sh", "-c", "while true; do sleep 1; echo hello; done"); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
err := waitForContainer("attacher", "-d", "busybox", "/bin/sh", "-c", "while true; do sleep 1; echo hello; done")
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
startDone := make(chan struct{})
|
||||
endDone := make(chan struct{})
|
||||
|
@ -84,7 +83,6 @@ func (s *DockerSuite) TestAttachMultipleAndRestart(c *check.C) {
|
|||
case <-time.After(attachWait):
|
||||
c.Fatalf("Attaches did not finish properly")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAttachTtyWithoutStdin(c *check.C) {
|
||||
|
@ -94,13 +92,6 @@ func (s *DockerSuite) TestAttachTtyWithoutStdin(c *check.C) {
|
|||
id := strings.TrimSpace(out)
|
||||
c.Assert(waitRun(id), check.IsNil)
|
||||
|
||||
defer func() {
|
||||
cmd := exec.Command(dockerBinary, "kill", id)
|
||||
if out, _, err := runCommandWithOutput(cmd); err != nil {
|
||||
c.Fatalf("failed to kill container: %v (%v)", out, err)
|
||||
}
|
||||
}()
|
||||
|
||||
done := make(chan error)
|
||||
go func() {
|
||||
defer close(done)
|
||||
|
@ -141,37 +132,21 @@ func (s *DockerSuite) TestAttachDisconnect(c *check.C) {
|
|||
}
|
||||
defer stdin.Close()
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
c.Assert(err, check.IsNil)
|
||||
defer stdout.Close()
|
||||
if err := cmd.Start(); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
c.Assert(cmd.Start(), check.IsNil)
|
||||
defer cmd.Process.Kill()
|
||||
|
||||
if _, err := stdin.Write([]byte("hello\n")); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
_, err = stdin.Write([]byte("hello\n"))
|
||||
c.Assert(err, check.IsNil)
|
||||
out, err = bufio.NewReader(stdout).ReadString('\n')
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
if strings.TrimSpace(out) != "hello" {
|
||||
c.Fatalf("expected 'hello', got %q", out)
|
||||
}
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(strings.TrimSpace(out), check.Equals, "hello")
|
||||
|
||||
if err := stdin.Close(); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
c.Assert(stdin.Close(), check.IsNil)
|
||||
|
||||
// Expect container to still be running after stdin is closed
|
||||
running, err := inspectField(id, "State.Running")
|
||||
if err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
if running != "true" {
|
||||
c.Fatal("expected container to still be running")
|
||||
}
|
||||
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(running, check.Equals, "true")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue