浏览代码

add TestContainerApiPause case

Signed-off-by: Yuan Sun <sunyuan3@huawei.com>
Yuan Sun 10 年之前
父节点
当前提交
8636a21991
共有 2 个文件被更改,包括 48 次插入3 次删除
  1. 45 3
      integration-cli/docker_api_containers_test.go
  2. 3 0
      integration-cli/docker_utils.go

+ 45 - 3
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")
+}

+ 3 - 0
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
 	}