add TestContainerApiPause case

Signed-off-by: Yuan Sun <sunyuan3@huawei.com>
This commit is contained in:
Yuan Sun 2015-04-10 09:14:01 +08:00
parent 404f81011b
commit 8636a21991
2 changed files with 48 additions and 3 deletions

View File

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

View File

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