Prechádzať zdrojové kódy

Refactor cleanup of paused test containers

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Brian Goff 8 rokov pred
rodič
commit
788c20668d

+ 3 - 3
integration-cli/docker_api_containers_test.go

@@ -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) {

+ 2 - 2
integration-cli/docker_cli_pause_test.go

@@ -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))
 

+ 6 - 20
integration-cli/docker_utils.go

@@ -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 {
-			return nil, err
-		}
-		slice := strings.Split(strings.TrimSpace(out), "\n")
-		return slice, err
+	if err != nil {
+		return nil, 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)
 	}
 }