Use of checkers on docker_cli_pause_test.go.
Signed-off-by: liaoqingwei <liaoqingwei@huawei.com>
This commit is contained in:
parent
7a19164c17
commit
851a533a82
1 changed files with 11 additions and 30 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/integration/checker"
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,30 +17,20 @@ func (s *DockerSuite) TestPause(c *check.C) {
|
||||||
|
|
||||||
dockerCmd(c, "pause", name)
|
dockerCmd(c, "pause", name)
|
||||||
pausedContainers, err := getSliceOfPausedContainers()
|
pausedContainers, err := getSliceOfPausedContainers()
|
||||||
if err != nil {
|
c.Assert(err, checker.IsNil)
|
||||||
c.Fatalf("error thrown while checking if containers were paused: %v", err)
|
c.Assert(len(pausedContainers), checker.Equals, 1)
|
||||||
}
|
|
||||||
if len(pausedContainers) != 1 {
|
|
||||||
c.Fatalf("there should be one paused container and not %d", len(pausedContainers))
|
|
||||||
}
|
|
||||||
|
|
||||||
dockerCmd(c, "unpause", name)
|
dockerCmd(c, "unpause", name)
|
||||||
|
|
||||||
out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
|
out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
|
||||||
events := strings.Split(out, "\n")
|
events := strings.Split(out, "\n")
|
||||||
if len(events) <= 1 {
|
c.Assert(len(events) > 1, checker.Equals, true)
|
||||||
c.Fatalf("Missing expected event")
|
|
||||||
}
|
|
||||||
|
|
||||||
pauseEvent := strings.Fields(events[len(events)-3])
|
pauseEvent := strings.Fields(events[len(events)-3])
|
||||||
unpauseEvent := strings.Fields(events[len(events)-2])
|
unpauseEvent := strings.Fields(events[len(events)-2])
|
||||||
|
|
||||||
if pauseEvent[len(pauseEvent)-1] != "pause" {
|
c.Assert(pauseEvent[len(pauseEvent)-1], checker.Equals, "pause")
|
||||||
c.Fatalf("event should be pause, not %#v", pauseEvent)
|
c.Assert(unpauseEvent[len(unpauseEvent)-1], checker.Equals, "unpause")
|
||||||
}
|
|
||||||
if unpauseEvent[len(unpauseEvent)-1] != "unpause" {
|
|
||||||
c.Fatalf("event should be unpause, not %#v", unpauseEvent)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,20 +47,14 @@ func (s *DockerSuite) TestPauseMultipleContainers(c *check.C) {
|
||||||
}
|
}
|
||||||
dockerCmd(c, append([]string{"pause"}, containers...)...)
|
dockerCmd(c, append([]string{"pause"}, containers...)...)
|
||||||
pausedContainers, err := getSliceOfPausedContainers()
|
pausedContainers, err := getSliceOfPausedContainers()
|
||||||
if err != nil {
|
c.Assert(err, checker.IsNil)
|
||||||
c.Fatalf("error thrown while checking if containers were paused: %v", err)
|
c.Assert(len(pausedContainers), checker.Equals, len(containers))
|
||||||
}
|
|
||||||
if len(pausedContainers) != len(containers) {
|
|
||||||
c.Fatalf("there should be %d paused container and not %d", len(containers), len(pausedContainers))
|
|
||||||
}
|
|
||||||
|
|
||||||
dockerCmd(c, append([]string{"unpause"}, containers...)...)
|
dockerCmd(c, append([]string{"unpause"}, containers...)...)
|
||||||
|
|
||||||
out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
|
out, _ := dockerCmd(c, "events", "--since=0", fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
|
||||||
events := strings.Split(out, "\n")
|
events := strings.Split(out, "\n")
|
||||||
if len(events) <= len(containers)*3-2 {
|
c.Assert(len(events) > len(containers)*3-2, checker.Equals, true)
|
||||||
c.Fatalf("Missing expected event")
|
|
||||||
}
|
|
||||||
|
|
||||||
pauseEvents := make([][]string, len(containers))
|
pauseEvents := make([][]string, len(containers))
|
||||||
unpauseEvents := make([][]string, len(containers))
|
unpauseEvents := make([][]string, len(containers))
|
||||||
|
@ -79,14 +64,10 @@ func (s *DockerSuite) TestPauseMultipleContainers(c *check.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, pauseEvent := range pauseEvents {
|
for _, pauseEvent := range pauseEvents {
|
||||||
if pauseEvent[len(pauseEvent)-1] != "pause" {
|
c.Assert(pauseEvent[len(pauseEvent)-1], checker.Equals, "pause")
|
||||||
c.Fatalf("event should be pause, not %#v", pauseEvent)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for _, unpauseEvent := range unpauseEvents {
|
for _, unpauseEvent := range unpauseEvents {
|
||||||
if unpauseEvent[len(unpauseEvent)-1] != "unpause" {
|
c.Assert(unpauseEvent[len(unpauseEvent)-1], checker.Equals, "unpause")
|
||||||
c.Fatalf("event should be unpause, not %#v", unpauseEvent)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue