Merge pull request #12569 from kostickm/12449-check-statusCode

Fixing statusCode checks for sockRequest
This commit is contained in:
Jessie Frazelle 2015-04-23 17:13:06 -07:00
commit 9d94d91ea7
12 changed files with 165 additions and 199 deletions

View file

@ -28,10 +28,9 @@ func (s *DockerSuite) TestContainerApiGetAll(c *check.C) {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
_, body, err := sockRequest("GET", "/containers/json?all=1", nil)
if err != nil {
c.Fatalf("GET all containers sockRequest failed: %v", err)
}
status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
var inspectJSON []struct {
Names []string
@ -57,10 +56,9 @@ func (s *DockerSuite) TestContainerApiGetExport(c *check.C) {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
_, body, err := sockRequest("GET", "/containers/"+name+"/export", nil)
if err != nil {
c.Fatalf("GET containers/export sockRequest failed: %v", err)
}
status, body, err := sockRequest("GET", "/containers/"+name+"/export", nil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
found := false
for tarReader := tar.NewReader(bytes.NewReader(body)); ; {
@ -90,10 +88,9 @@ func (s *DockerSuite) TestContainerApiGetChanges(c *check.C) {
c.Fatalf("Error on container creation: %v, output: %q", err, out)
}
_, body, err := sockRequest("GET", "/containers/"+name+"/changes", nil)
if err != nil {
c.Fatalf("GET containers/changes sockRequest failed: %v", err)
}
status, body, err := sockRequest("GET", "/containers/"+name+"/changes", nil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
changes := []struct {
Kind int
@ -122,17 +119,17 @@ func (s *DockerSuite) TestContainerApiStartVolumeBinds(c *check.C) {
"Volumes": map[string]struct{}{"/tmp": {}},
}
if status, _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && status != http.StatusCreated {
c.Fatal(err)
}
status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
c.Assert(status, check.Equals, http.StatusCreated)
c.Assert(err, check.IsNil)
bindPath := randomUnixTmpDirPath("test")
config = map[string]interface{}{
"Binds": []string{bindPath + ":/tmp"},
}
if status, _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && status != http.StatusNoContent {
c.Fatal(err)
}
status, _, err = sockRequest("POST", "/containers/"+name+"/start", config)
c.Assert(status, check.Equals, http.StatusNoContent)
c.Assert(err, check.IsNil)
pth, err := inspectFieldMap(name, "Volumes", "/tmp")
if err != nil {
@ -152,9 +149,9 @@ func (s *DockerSuite) TestContainerApiStartDupVolumeBinds(c *check.C) {
"Volumes": map[string]struct{}{"/tmp": {}},
}
if status, _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && status != http.StatusCreated {
c.Fatal(err)
}
status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
c.Assert(status, check.Equals, http.StatusCreated)
c.Assert(err, check.IsNil)
bindPath1 := randomUnixTmpDirPath("test1")
bindPath2 := randomUnixTmpDirPath("test2")
@ -162,14 +159,15 @@ func (s *DockerSuite) TestContainerApiStartDupVolumeBinds(c *check.C) {
config = map[string]interface{}{
"Binds": []string{bindPath1 + ":/tmp", bindPath2 + ":/tmp"},
}
if _, body, err := sockRequest("POST", "/containers/"+name+"/start", config); err == nil {
c.Fatal("expected container start to fail when duplicate volume binds to same container path")
} else {
if !strings.Contains(string(body), "Duplicate volume") {
c.Fatalf("Expected failure due to duplicate bind mounts to same path, instead got: %q with error: %v", string(body), err)
}
status, body, err := sockRequest("POST", "/containers/"+name+"/start", config)
c.Assert(status, check.Equals, http.StatusInternalServerError)
c.Assert(err, check.IsNil)
if !strings.Contains(string(body), "Duplicate volume") {
c.Fatalf("Expected failure due to duplicate bind mounts to same path, instead got: %q with error: %v", string(body), err)
}
}
func (s *DockerSuite) TestContainerApiStartVolumesFrom(c *check.C) {
volName := "voltst"
volPath := "/tmp"
@ -184,16 +182,16 @@ func (s *DockerSuite) TestContainerApiStartVolumesFrom(c *check.C) {
"Volumes": map[string]struct{}{volPath: {}},
}
if status, _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && status != http.StatusCreated {
c.Fatal(err)
}
status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
c.Assert(status, check.Equals, http.StatusCreated)
c.Assert(err, check.IsNil)
config = map[string]interface{}{
"VolumesFrom": []string{volName},
}
if status, _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && status != http.StatusNoContent {
c.Fatal(err)
}
status, _, err = sockRequest("POST", "/containers/"+name+"/start", config)
c.Assert(status, check.Equals, http.StatusNoContent)
c.Assert(err, check.IsNil)
pth, err := inspectFieldMap(name, "Volumes", volPath)
if err != nil {
@ -225,18 +223,18 @@ func (s *DockerSuite) TestVolumesFromHasPriority(c *check.C) {
"Volumes": map[string]struct{}{volPath: {}},
}
if status, _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && status != http.StatusCreated {
c.Fatal(err)
}
status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
c.Assert(status, check.Equals, http.StatusCreated)
c.Assert(err, check.IsNil)
bindPath := randomUnixTmpDirPath("test")
config = map[string]interface{}{
"VolumesFrom": []string{volName},
"Binds": []string{bindPath + ":/tmp"},
}
if status, _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && status != http.StatusNoContent {
c.Fatal(err)
}
status, _, err = sockRequest("POST", "/containers/"+name+"/start", config)
c.Assert(status, check.Equals, http.StatusNoContent)
c.Assert(err, check.IsNil)
pth, err := inspectFieldMap(name, "Volumes", volPath)
if err != nil {
@ -267,7 +265,9 @@ func (s *DockerSuite) TestGetContainerStats(c *check.C) {
}
bc := make(chan b, 1)
go func() {
_, body, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
status, body, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
bc <- b{body, err}
}()
@ -309,10 +309,9 @@ func (s *DockerSuite) TestGetStoppedContainerStats(c *check.C) {
go func() {
// We'll never get return for GET stats from sockRequest as of now,
// just send request and see if panic or error would happen on daemon side.
_, _, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
if err != nil {
c.Fatal(err)
}
status, _, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
}()
// allow some time to send request and let daemon deal with it
@ -340,11 +339,10 @@ func (s *DockerSuite) TestBuildApiDockerfilePath(c *check.C) {
c.Fatalf("failed to close tar archive: %v", err)
}
_, body, err := sockRequestRaw("POST", "/build?dockerfile=../Dockerfile", buffer, "application/x-tar")
if err == nil {
out, _ := readBody(body)
c.Fatalf("Build was supposed to fail: %s", out)
}
status, body, err := sockRequestRaw("POST", "/build?dockerfile=../Dockerfile", buffer, "application/x-tar")
c.Assert(status, check.Equals, http.StatusInternalServerError)
c.Assert(err, check.IsNil)
out, err := readBody(body)
if err != nil {
c.Fatal(err)
@ -367,10 +365,10 @@ RUN find /tmp/`,
}
defer server.Close()
_, body, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+server.URL()+"/testD", nil, "application/json")
if err != nil {
c.Fatalf("Build failed: %s", err)
}
status, body, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+server.URL()+"/testD", nil, "application/json")
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
buf, err := readBody(body)
if err != nil {
c.Fatal(err)
@ -395,11 +393,10 @@ RUN echo from dockerfile`,
}
defer git.Close()
_, body, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
if err != nil {
buf, _ := readBody(body)
c.Fatalf("Build failed: %s\n%q", err, buf)
}
status, body, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
buf, err := readBody(body)
if err != nil {
c.Fatal(err)
@ -424,11 +421,10 @@ RUN echo from Dockerfile`,
defer git.Close()
// Make sure it tries to 'dockerfile' query param value
_, body, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+git.RepoURL, nil, "application/json")
if err != nil {
buf, _ := readBody(body)
c.Fatalf("Build failed: %s\n%q", err, buf)
}
status, body, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+git.RepoURL, nil, "application/json")
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
buf, err := readBody(body)
if err != nil {
c.Fatal(err)
@ -454,10 +450,10 @@ RUN echo from dockerfile`,
defer git.Close()
// Make sure it tries to 'dockerfile' query param value
_, body, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
if err != nil {
c.Fatalf("Build failed: %s", err)
}
status, body, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
buf, err := readBody(body)
if err != nil {
c.Fatal(err)
@ -487,11 +483,10 @@ func (s *DockerSuite) TestBuildApiDockerfileSymlink(c *check.C) {
c.Fatalf("failed to close tar archive: %v", err)
}
_, body, err := sockRequestRaw("POST", "/build", buffer, "application/x-tar")
if err == nil {
out, _ := readBody(body)
c.Fatalf("Build was supposed to fail: %s", out)
}
status, body, err := sockRequestRaw("POST", "/build", buffer, "application/x-tar")
c.Assert(status, check.Equals, http.StatusInternalServerError)
c.Assert(err, check.IsNil)
out, err := readBody(body)
if err != nil {
c.Fatal(err)
@ -524,9 +519,9 @@ func (s *DockerSuite) TestPostContainerBindNormalVolume(c *check.C) {
}
bindSpec := map[string][]string{"Binds": {fooDir + ":/foo"}}
if status, _, err := sockRequest("POST", "/containers/two/start", bindSpec); err != nil && status != http.StatusNoContent {
c.Fatal(err)
}
status, _, err := sockRequest("POST", "/containers/two/start", bindSpec)
c.Assert(status, check.Equals, http.StatusNoContent)
c.Assert(err, check.IsNil)
fooDir2, err := inspectFieldMap("two", "Volumes", "/foo")
if err != nil {
@ -548,9 +543,9 @@ func (s *DockerSuite) TestContainerApiPause(c *check.C) {
}
ContainerID := strings.TrimSpace(out)
if status, _, err := sockRequest("POST", "/containers/"+ContainerID+"/pause", nil); err != nil && status != http.StatusNoContent {
c.Fatalf("POST a container pause: sockRequest failed: %v", err)
}
status, _, err := sockRequest("POST", "/containers/"+ContainerID+"/pause", nil)
c.Assert(status, check.Equals, http.StatusNoContent)
c.Assert(err, check.IsNil)
pausedContainers, err := getSliceOfPausedContainers()
@ -562,9 +557,9 @@ func (s *DockerSuite) TestContainerApiPause(c *check.C) {
c.Fatalf("there should be one paused container and not %d", len(pausedContainers))
}
if status, _, err := sockRequest("POST", "/containers/"+ContainerID+"/unpause", nil); err != nil && status != http.StatusNoContent {
c.Fatalf("POST a container pause: sockRequest failed: %v", err)
}
status, _, err = sockRequest("POST", "/containers/"+ContainerID+"/unpause", nil)
c.Assert(status, check.Equals, http.StatusNoContent)
c.Assert(err, check.IsNil)
pausedContainers, err = getSliceOfPausedContainers()
@ -592,10 +587,10 @@ func (s *DockerSuite) TestContainerApiTop(c *check.C) {
Processes [][]string
}
var top topResp
_, b, err := sockRequest("GET", "/containers/"+id+"/top?ps_args=aux", nil)
if err != nil {
c.Fatal(err)
}
status, b, err := sockRequest("GET", "/containers/"+id+"/top?ps_args=aux", nil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
if err := json.Unmarshal(b, &top); err != nil {
c.Fatal(err)
}
@ -626,10 +621,9 @@ func (s *DockerSuite) TestContainerApiCommit(c *check.C) {
id := strings.TrimSpace(string(out))
name := "testcommit" + stringid.GenerateRandomID()
_, b, err := sockRequest("POST", "/commit?repo="+name+"&testtag=tag&container="+id, nil)
if err != nil && !strings.Contains(err.Error(), "200 OK: 201") {
c.Fatal(err)
}
status, b, err := sockRequest("POST", "/commit?repo="+name+"&testtag=tag&container="+id, nil)
c.Assert(status, check.Equals, http.StatusCreated)
c.Assert(err, check.IsNil)
type resp struct {
Id string
@ -660,10 +654,10 @@ func (s *DockerSuite) TestContainerApiCreate(c *check.C) {
"Cmd": []string{"/bin/sh", "-c", "touch /test && ls /test"},
}
_, b, err := sockRequest("POST", "/containers/create", config)
if err != nil && !strings.Contains(err.Error(), "200 OK: 201") {
c.Fatal(err)
}
status, b, err := sockRequest("POST", "/containers/create", config)
c.Assert(status, check.Equals, http.StatusCreated)
c.Assert(err, check.IsNil)
type createResp struct {
Id string
}
@ -736,26 +730,21 @@ func (s *DockerSuite) TestContainerApiVerifyHeader(c *check.C) {
}
// Try with no content-type
_, body, err := create("")
if err == nil {
b, _ := readBody(body)
c.Fatalf("expected error when content-type is not set: %q", string(b))
}
status, body, err := create("")
c.Assert(status, check.Equals, http.StatusInternalServerError)
c.Assert(err, check.IsNil)
body.Close()
// Try with wrong content-type
_, body, err = create("application/xml")
if err == nil {
b, _ := readBody(body)
c.Fatalf("expected error when content-type is not set: %q", string(b))
}
status, body, err = create("application/xml")
c.Assert(status, check.Equals, http.StatusInternalServerError)
c.Assert(err, check.IsNil)
body.Close()
// now application/json
_, body, err = create("application/json")
if err != nil && !strings.Contains(err.Error(), "200 OK: 201") {
b, _ := readBody(body)
c.Fatalf("%v - %q", err, string(b))
}
status, body, err = create("application/json")
c.Assert(status, check.Equals, http.StatusCreated)
c.Assert(err, check.IsNil)
body.Close()
}
@ -786,11 +775,9 @@ func (s *DockerSuite) TestContainerApiPostCreateNull(c *check.C) {
"NetworkDisabled":false,
"OnBuild":null}`
_, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
if err != nil && !strings.Contains(err.Error(), "200 OK: 201") {
b, _ := readBody(body)
c.Fatal(err, string(b))
}
status, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
c.Assert(status, check.Equals, http.StatusCreated)
c.Assert(err, check.IsNil)
b, err := readBody(body)
if err != nil {
@ -822,16 +809,14 @@ func (s *DockerSuite) TestCreateWithTooLowMemoryLimit(c *check.C) {
"Memory": 524287
}`
_, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
status, body, _ := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
b, err2 := readBody(body)
if err2 != nil {
c.Fatal(err2)
}
if err == nil || !strings.Contains(string(b), "Minimum memory limit allowed is 4MB") {
c.Errorf("Memory limit is smaller than the allowed limit. Container creation should've failed!")
}
c.Assert(status, check.Equals, http.StatusInternalServerError)
c.Assert(strings.Contains(string(b), "Minimum memory limit allowed is 4MB"), check.Equals, true)
}
func (s *DockerSuite) TestStartWithTooLowMemoryLimit(c *check.C) {
@ -847,13 +832,12 @@ func (s *DockerSuite) TestStartWithTooLowMemoryLimit(c *check.C) {
"Memory": 524287
}`
_, body, err := sockRequestRaw("POST", "/containers/"+containerID+"/start", strings.NewReader(config), "application/json")
status, body, _ := sockRequestRaw("POST", "/containers/"+containerID+"/start", strings.NewReader(config), "application/json")
b, err2 := readBody(body)
if err2 != nil {
c.Fatal(err2)
}
if err == nil || !strings.Contains(string(b), "Minimum memory limit allowed is 4MB") {
c.Errorf("Memory limit is smaller than the allowed limit. Container creation should've failed!")
}
c.Assert(status, check.Equals, http.StatusInternalServerError)
c.Assert(strings.Contains(string(b), "Minimum memory limit allowed is 4MB"), check.Equals, true)
}

View file

@ -18,10 +18,6 @@ func (s *DockerSuite) TestExecResizeApiHeightWidthNoInt(c *check.C) {
endpoint := "/exec/" + cleanedContainerID + "/resize?h=foo&w=bar"
status, _, err := sockRequest("POST", endpoint, nil)
if err == nil {
c.Fatal("Expected exec resize Request to fail")
}
if status != http.StatusInternalServerError {
c.Fatalf("Status expected %d, got %d", http.StatusInternalServerError, status)
}
c.Assert(status, check.Equals, http.StatusInternalServerError)
c.Assert(err, check.IsNil)
}

View file

@ -5,6 +5,7 @@ package main
import (
"bytes"
"fmt"
"net/http"
"os/exec"
"github.com/go-check/check"
@ -18,8 +19,11 @@ func (s *DockerSuite) TestExecApiCreateNoCmd(c *check.C) {
c.Fatal(out, err)
}
_, body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": nil})
if err == nil || !bytes.Contains(body, []byte("No exec command specified")) {
c.Fatalf("Expected error when creating exec command with no Cmd specified: %q", err)
status, body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": nil})
c.Assert(status, check.Equals, http.StatusInternalServerError)
c.Assert(err, check.IsNil)
if !bytes.Contains(body, []byte("No exec command specified")) {
c.Fatalf("Expected message when creating exec command with no Cmd specified")
}
}

View file

@ -2,6 +2,7 @@ package main
import (
"encoding/json"
"net/http"
"net/url"
"os/exec"
"strings"
@ -11,10 +12,9 @@ import (
)
func (s *DockerSuite) TestLegacyImages(c *check.C) {
_, body, err := sockRequest("GET", "/v1.6/images/json", nil)
if err != nil {
c.Fatalf("Error on GET: %s", err)
}
status, body, err := sockRequest("GET", "/v1.6/images/json", nil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
images := []types.LegacyImage{}
if err = json.Unmarshal(body, &images); err != nil {
@ -40,10 +40,10 @@ func (s *DockerSuite) TestApiImagesFilter(c *check.C) {
getImages := func(filter string) []image {
v := url.Values{}
v.Set("filter", filter)
_, b, err := sockRequest("GET", "/images/json?"+v.Encode(), nil)
if err != nil {
c.Fatal(err)
}
status, b, err := sockRequest("GET", "/images/json?"+v.Encode(), nil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
var images []image
if err := json.Unmarshal(b, &images); err != nil {
c.Fatal(err)
@ -76,20 +76,20 @@ func (s *DockerSuite) TestApiImagesSaveAndLoad(c *check.C) {
id := strings.TrimSpace(out)
defer deleteImages("saveandload")
_, body, err := sockRequestRaw("GET", "/images/"+id+"/get", nil, "")
if err != nil {
c.Fatal(err)
}
status, body, err := sockRequestRaw("GET", "/images/"+id+"/get", nil, "")
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
defer body.Close()
if out, err := exec.Command(dockerBinary, "rmi", id).CombinedOutput(); err != nil {
c.Fatal(err, out)
}
_, loadBody, err := sockRequestRaw("POST", "/images/load", body, "application/x-tar")
if err != nil {
c.Fatal(err)
}
status, loadBody, err := sockRequestRaw("POST", "/images/load", body, "application/x-tar")
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
defer loadBody.Close()
inspectOut, err := exec.Command(dockerBinary, "inspect", "--format='{{ .Id }}'", id).CombinedOutput()

View file

@ -10,10 +10,9 @@ import (
func (s *DockerSuite) TestInfoApi(c *check.C) {
endpoint := "/info"
statusCode, body, err := sockRequest("GET", endpoint, nil)
if err != nil || statusCode != http.StatusOK {
c.Fatalf("Expected %d from info request, got %d", http.StatusOK, statusCode)
}
status, body, err := sockRequest("GET", endpoint, nil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
// always shown fields
stringsToCheck := []string{

View file

@ -2,6 +2,7 @@ package main
import (
"encoding/json"
"net/http"
"os/exec"
"strings"
@ -26,10 +27,9 @@ func (s *DockerSuite) TestInspectApiContainerResponse(c *check.C) {
if testVersion != "latest" {
endpoint = "/" + testVersion + endpoint
}
_, body, err := sockRequest("GET", endpoint, nil)
if err != nil {
c.Fatalf("sockRequest failed for %s version: %v", testVersion, err)
}
status, body, err := sockRequest("GET", endpoint, nil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
var inspectJSON map[string]interface{}
if err = json.Unmarshal(body, &inspectJSON); err != nil {

View file

@ -17,11 +17,9 @@ func (s *DockerSuite) TestLogsApiWithStdout(c *check.C) {
c.Fatal(out, err)
}
statusCode, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&timestamps=1", name), nil)
if err != nil || statusCode != http.StatusOK {
c.Fatalf("Expected %d from logs request, got %d", http.StatusOK, statusCode)
}
status, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&timestamps=1", name), nil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
if !bytes.Contains(body, []byte(name)) {
c.Fatalf("Expected %s, got %s", name, string(body[:]))
@ -35,11 +33,9 @@ func (s *DockerSuite) TestLogsApiNoStdoutNorStderr(c *check.C) {
c.Fatal(out, err)
}
statusCode, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs", name), nil)
if err == nil || statusCode != http.StatusBadRequest {
c.Fatalf("Expected %d from logs request, got %d", http.StatusBadRequest, statusCode)
}
status, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs", name), nil)
c.Assert(status, check.Equals, http.StatusBadRequest)
c.Assert(err, check.IsNil)
expected := "Bad parameters: you must choose at least one stream"
if !bytes.Contains(body, []byte(expected)) {

View file

@ -17,10 +17,9 @@ func (s *DockerSuite) TestResizeApiResponse(c *check.C) {
cleanedContainerID := strings.TrimSpace(out)
endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
_, _, err = sockRequest("POST", endpoint, nil)
if err != nil {
c.Fatalf("resize Request failed %v", err)
}
status, _, err := sockRequest("POST", endpoint, nil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
}
func (s *DockerSuite) TestResizeApiHeightWidthNoInt(c *check.C) {
@ -33,12 +32,8 @@ func (s *DockerSuite) TestResizeApiHeightWidthNoInt(c *check.C) {
endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar"
status, _, err := sockRequest("POST", endpoint, nil)
if err == nil {
c.Fatal("Expected resize Request to fail")
}
if status != http.StatusInternalServerError {
c.Fatalf("Status expected %d, got %d", http.StatusInternalServerError, status)
}
c.Assert(status, check.Equals, http.StatusInternalServerError)
c.Assert(err, check.IsNil)
}
func (s *DockerSuite) TestResizeApiResponseWhenContainerNotStarted(c *check.C) {
@ -57,10 +52,10 @@ func (s *DockerSuite) TestResizeApiResponseWhenContainerNotStarted(c *check.C) {
}
endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
_, body, err := sockRequest("POST", endpoint, nil)
if err == nil {
c.Fatalf("resize should fail when container is not started")
}
status, body, err := sockRequest("POST", endpoint, nil)
c.Assert(status, check.Equals, http.StatusInternalServerError)
c.Assert(err, check.IsNil)
if !strings.Contains(string(body), "Cannot resize container") && !strings.Contains(string(body), cleanedContainerID) {
c.Fatalf("resize should fail with message 'Cannot resize container' but instead received %s", string(body))
}

View file

@ -2,6 +2,7 @@ package main
import (
"encoding/json"
"net/http"
"github.com/docker/docker/api/types"
"github.com/docker/docker/autogen/dockerversion"
@ -9,10 +10,10 @@ import (
)
func (s *DockerSuite) TestGetVersion(c *check.C) {
_, body, err := sockRequest("GET", "/version", nil)
if err != nil {
c.Fatal(err)
}
status, body, err := sockRequest("GET", "/version", nil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
var v types.Version
if err := json.Unmarshal(body, &v); err != nil {
c.Fatal(err)

View file

@ -60,13 +60,8 @@ func (s *DockerSuite) TestRmRunningContainerCheckError409(c *check.C) {
endpoint := "/containers/foo"
status, _, err := sockRequest("DELETE", endpoint, nil)
if err == nil {
c.Fatalf("Expected error, can't rm a running container")
} else if status != http.StatusConflict {
c.Fatalf("Expected error to contain '409 Conflict' but found %s", err)
}
c.Assert(status, check.Equals, http.StatusConflict)
c.Assert(err, check.IsNil)
}
func (s *DockerSuite) TestRmForceRemoveRunningContainer(c *check.C) {

View file

@ -350,9 +350,6 @@ func sockRequestRaw(method, endpoint string, data io.Reader, ct string) (int, io
defer client.Close()
return resp.Body.Close()
})
if resp.StatusCode != http.StatusOK {
return resp.StatusCode, body, fmt.Errorf("received status != 200 OK: %s", resp.Status)
}
return resp.StatusCode, body, err
}
@ -1062,10 +1059,9 @@ func daemonTime(c *check.C) time.Time {
return time.Now()
}
_, body, err := sockRequest("GET", "/info", nil)
if err != nil {
c.Fatalf("daemonTime: failed to get /info: %v", err)
}
status, body, err := sockRequest("GET", "/info", nil)
c.Assert(status, check.Equals, http.StatusOK)
c.Assert(err, check.IsNil)
type infoJSON struct {
SystemTime string

View file

@ -58,8 +58,8 @@ var (
func() bool {
if daemonExecDriver == "" {
// get daemon info
_, body, err := sockRequest("GET", "/info", nil)
if err != nil {
status, body, err := sockRequest("GET", "/info", nil)
if err != nil || status != http.StatusOK {
log.Fatalf("sockRequest failed for /info: %v", err)
}