1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Refactor cleanup of paused test containers

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff 2016-12-20 16:26:55 -05:00
parent d477a24ec5
commit 788c20668d
3 changed files with 11 additions and 25 deletions

View file

@ -354,7 +354,7 @@ func (s *DockerSuite) TestContainerAPIPause(c *check.C) {
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusNoContent)
pausedContainers, err := getSliceOfPausedContainers()
pausedContainers, err := getPausedContainers()
c.Assert(err, checker.IsNil, check.Commentf("error thrown while checking if containers were paused"))
if len(pausedContainers) != 1 || stringid.TruncateID(ContainerID) != pausedContainers[0] {
@ -365,9 +365,9 @@ func (s *DockerSuite) TestContainerAPIPause(c *check.C) {
c.Assert(err, checker.IsNil)
c.Assert(status, checker.Equals, http.StatusNoContent)
pausedContainers, err = getSliceOfPausedContainers()
pausedContainers, err = getPausedContainers()
c.Assert(err, checker.IsNil, check.Commentf("error thrown while checking if containers were paused"))
c.Assert(pausedContainers, checker.IsNil, check.Commentf("There should be no paused container."))
c.Assert(pausedContainers, checker.HasLen, 0, check.Commentf("There should be no paused container."))
}
func (s *DockerSuite) TestContainerAPITop(c *check.C) {

View file

@ -15,7 +15,7 @@ func (s *DockerSuite) TestPause(c *check.C) {
runSleepingContainer(c, "-d", "--name", name)
dockerCmd(c, "pause", name)
pausedContainers, err := getSliceOfPausedContainers()
pausedContainers, err := getPausedContainers()
c.Assert(err, checker.IsNil)
c.Assert(len(pausedContainers), checker.Equals, 1)
@ -41,7 +41,7 @@ func (s *DockerSuite) TestPauseMultipleContainers(c *check.C) {
runSleepingContainer(c, "-d", "--name", name)
}
dockerCmd(c, append([]string{"pause"}, containers...)...)
pausedContainers, err := getSliceOfPausedContainers()
pausedContainers, err := getPausedContainers()
c.Assert(err, checker.IsNil)
c.Assert(len(pausedContainers), checker.Equals, len(containers))

View file

@ -344,26 +344,17 @@ func deleteAllImages(c *check.C) {
}
}
func getPausedContainers() (string, error) {
func getPausedContainers() ([]string, error) {
getPausedContainersCmd := exec.Command(dockerBinary, "ps", "-f", "status=paused", "-q", "-a")
out, exitCode, err := runCommandWithOutput(getPausedContainersCmd)
if exitCode != 0 && err == nil {
err = fmt.Errorf("failed to get a list of paused containers: %v\n", out)
}
return out, err
}
func getSliceOfPausedContainers() ([]string, error) {
out, err := getPausedContainers()
if err == nil {
if len(out) == 0 {
if err != nil {
return nil, err
}
slice := strings.Split(strings.TrimSpace(out), "\n")
return slice, err
}
return []string{out}, err
return strings.Fields(out), nil
}
func unpauseContainer(c *check.C, container string) {
@ -373,12 +364,7 @@ func unpauseContainer(c *check.C, container string) {
func unpauseAllContainers(c *check.C) {
containers, err := getPausedContainers()
c.Assert(err, checker.IsNil, check.Commentf("containers: %v", containers))
containers = strings.Replace(containers, "\n", " ", -1)
containers = strings.Trim(containers, " ")
containerList := strings.Split(containers, " ")
for _, value := range containerList {
for _, value := range containers {
unpauseContainer(c, value)
}
}