From 8636a219911536123decb547dab9bf50ebb2c8f8 Mon Sep 17 00:00:00 2001 From: Yuan Sun Date: Fri, 10 Apr 2015 09:14:01 +0800 Subject: [PATCH] add TestContainerApiPause case Signed-off-by: Yuan Sun --- integration-cli/docker_api_containers_test.go | 48 +++++++++++++++++-- integration-cli/docker_utils.go | 3 ++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/integration-cli/docker_api_containers_test.go b/integration-cli/docker_api_containers_test.go index 02d069f598..07793a8fca 100644 --- a/integration-cli/docker_api_containers_test.go +++ b/integration-cli/docker_api_containers_test.go @@ -3,14 +3,14 @@ package main import ( "bytes" "encoding/json" + "github.com/docker/docker/api/types" + "github.com/docker/docker/pkg/stringid" + "github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar" "io" "os/exec" "strings" "testing" "time" - - "github.com/docker/docker/api/types" - "github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar" ) func TestContainerApiGetAll(t *testing.T) { @@ -553,3 +553,45 @@ func TestPostContainerBindNormalVolume(t *testing.T) { logDone("container REST API - can use path from normal volume as bind-mount to overwrite another volume") } + +func TestContainerApiPause(t *testing.T) { + defer deleteAllContainers() + defer unpauseAllContainers() + runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sleep", "30") + out, _, err := runCommandWithOutput(runCmd) + + if err != nil { + t.Fatalf("failed to create a container: %s, %v", out, err) + } + ContainerID := strings.TrimSpace(out) + + if _, err = sockRequest("POST", "/containers/"+ContainerID+"/pause", nil); err != nil && !strings.Contains(err.Error(), "204 No Content") { + t.Fatalf("POST a container pause: sockRequest failed: %v", err) + } + + pausedContainers, err := getSliceOfPausedContainers() + + if err != nil { + t.Fatalf("error thrown while checking if containers were paused: %v", err) + } + + if len(pausedContainers) != 1 || stringid.TruncateID(ContainerID) != pausedContainers[0] { + t.Fatalf("there should be one paused container and not %d", len(pausedContainers)) + } + + if _, err = sockRequest("POST", "/containers/"+ContainerID+"/unpause", nil); err != nil && !strings.Contains(err.Error(), "204 No Content") { + t.Fatalf("POST a container pause: sockRequest failed: %v", err) + } + + pausedContainers, err = getSliceOfPausedContainers() + + if err != nil { + t.Fatalf("error thrown while checking if containers were paused: %v", err) + } + + if pausedContainers != nil { + t.Fatalf("There should be no paused container.") + } + + logDone("container REST API - check POST containers/pause nad unpause") +} diff --git a/integration-cli/docker_utils.go b/integration-cli/docker_utils.go index 843a07a20e..943c1e02a4 100644 --- a/integration-cli/docker_utils.go +++ b/integration-cli/docker_utils.go @@ -389,6 +389,9 @@ func getPausedContainers() (string, error) { 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 }