mirror of
https://github.com/moby/moby.git
synced 2025-07-30 18:23:29 +03:00
Add a new request package in integration-cli
The goal is to remove function from `docker_utils.go` and setup simple, one-responsability package that can be well tested ; and to ease writing request. This moves all the calls to `sockRequest` (and similar methods) to their counterpart in the `request` package. This introduce `request.Do` to write easier request (with functional argument to easily augment the request) with some pre-defined function for the most used http method (i.e. `request.Get`, `request.Post` and `request.Delete`). Few of the `sockRequest` call have been moved to `request.Do` (and `Get`, etc.) to showcase the usage of the package. There is still a whole lot to do. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
@ -8,7 +8,6 @@ import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -22,6 +21,7 @@ import (
|
||||
mounttypes "github.com/docker/docker/api/types/mount"
|
||||
networktypes "github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/request"
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
"github.com/docker/docker/pkg/mount"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
@ -37,7 +37,7 @@ func (s *DockerSuite) TestContainerAPIGetAll(c *check.C) {
|
||||
name := "getall"
|
||||
dockerCmd(c, "run", "--name", name, "busybox", "true")
|
||||
|
||||
status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
|
||||
status, body, err := request.SockRequest("GET", "/containers/json?all=1", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusOK)
|
||||
|
||||
@ -57,7 +57,7 @@ func (s *DockerSuite) TestContainerAPIGetAll(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPIGetJSONNoFieldsOmitted(c *check.C) {
|
||||
dockerCmd(c, "run", "busybox", "true")
|
||||
|
||||
status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
|
||||
status, body, err := request.SockRequest("GET", "/containers/json?all=1", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusOK)
|
||||
|
||||
@ -98,7 +98,7 @@ func (s *DockerSuite) TestContainerAPIPsOmitFields(c *check.C) {
|
||||
port := 80
|
||||
runSleepingContainer(c, "--name", name, "--expose", strconv.Itoa(port))
|
||||
|
||||
status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
|
||||
status, body, err := request.SockRequest("GET", "/containers/json?all=1", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusOK)
|
||||
|
||||
@ -130,7 +130,7 @@ func (s *DockerSuite) TestContainerAPIGetExport(c *check.C) {
|
||||
name := "exportcontainer"
|
||||
dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test")
|
||||
|
||||
status, body, err := sockRequest("GET", "/containers/"+name+"/export", nil)
|
||||
status, body, err := request.SockRequest("GET", "/containers/"+name+"/export", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusOK)
|
||||
|
||||
@ -154,7 +154,7 @@ func (s *DockerSuite) TestContainerAPIGetChanges(c *check.C) {
|
||||
name := "changescontainer"
|
||||
dockerCmd(c, "run", "--name", name, "busybox", "rm", "/etc/passwd")
|
||||
|
||||
status, body, err := sockRequest("GET", "/containers/"+name+"/changes", nil)
|
||||
status, body, err := request.SockRequest("GET", "/containers/"+name+"/changes", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusOK)
|
||||
|
||||
@ -187,7 +187,7 @@ func (s *DockerSuite) TestGetContainerStats(c *check.C) {
|
||||
}
|
||||
bc := make(chan b, 1)
|
||||
go func() {
|
||||
status, body, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
|
||||
status, body, err := request.SockRequest("GET", "/containers/"+name+"/stats", nil, daemonHost())
|
||||
bc <- b{status, body, err}
|
||||
}()
|
||||
|
||||
@ -218,7 +218,7 @@ func (s *DockerSuite) TestGetContainerStatsRmRunning(c *check.C) {
|
||||
buf := &testutil.ChannelBuffer{make(chan []byte, 1)}
|
||||
defer buf.Close()
|
||||
|
||||
_, body, err := sockRequestRaw("GET", "/containers/"+id+"/stats?stream=1", nil, "application/json")
|
||||
_, body, err := request.SockRequestRaw("GET", "/containers/"+id+"/stats?stream=1", nil, "application/json", daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer body.Close()
|
||||
|
||||
@ -257,7 +257,7 @@ func (s *DockerSuite) TestGetContainerStatsStream(c *check.C) {
|
||||
}
|
||||
bc := make(chan b, 1)
|
||||
go func() {
|
||||
status, body, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
|
||||
status, body, err := request.SockRequest("GET", "/containers/"+name+"/stats", nil, daemonHost())
|
||||
bc <- b{status, body, err}
|
||||
}()
|
||||
|
||||
@ -293,7 +293,7 @@ func (s *DockerSuite) TestGetContainerStatsNoStream(c *check.C) {
|
||||
}
|
||||
bc := make(chan b, 1)
|
||||
go func() {
|
||||
status, body, err := sockRequest("GET", "/containers/"+name+"/stats?stream=0", nil)
|
||||
status, body, err := request.SockRequest("GET", "/containers/"+name+"/stats?stream=0", nil, daemonHost())
|
||||
bc <- b{status, body, err}
|
||||
}()
|
||||
|
||||
@ -329,7 +329,7 @@ func (s *DockerSuite) TestGetStoppedContainerStats(c *check.C) {
|
||||
// We expect an immediate response, but if it's not immediate, the test would hang, so put it in a goroutine
|
||||
// below we'll check this on a timeout.
|
||||
go func() {
|
||||
resp, body, err := sockRequestRaw("GET", "/containers/"+name+"/stats", nil, "")
|
||||
resp, body, err := request.SockRequestRaw("GET", "/containers/"+name+"/stats", nil, "", daemonHost())
|
||||
body.Close()
|
||||
chResp <- stats{resp.StatusCode, err}
|
||||
}()
|
||||
@ -350,7 +350,7 @@ func (s *DockerSuite) TestContainerAPIPause(c *check.C) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "sleep", "30")
|
||||
ContainerID := strings.TrimSpace(out)
|
||||
|
||||
status, _, err := sockRequest("POST", "/containers/"+ContainerID+"/pause", nil)
|
||||
status, _, err := request.SockRequest("POST", "/containers/"+ContainerID+"/pause", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusNoContent)
|
||||
|
||||
@ -361,7 +361,7 @@ func (s *DockerSuite) TestContainerAPIPause(c *check.C) {
|
||||
c.Fatalf("there should be one paused container and not %d", len(pausedContainers))
|
||||
}
|
||||
|
||||
status, _, err = sockRequest("POST", "/containers/"+ContainerID+"/unpause", nil)
|
||||
status, _, err = request.SockRequest("POST", "/containers/"+ContainerID+"/unpause", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusNoContent)
|
||||
|
||||
@ -381,7 +381,7 @@ func (s *DockerSuite) TestContainerAPITop(c *check.C) {
|
||||
Processes [][]string
|
||||
}
|
||||
var top topResp
|
||||
status, b, err := sockRequest("GET", "/containers/"+id+"/top?ps_args=aux", nil)
|
||||
status, b, err := request.SockRequest("GET", "/containers/"+id+"/top?ps_args=aux", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusOK)
|
||||
c.Assert(json.Unmarshal(b, &top), checker.IsNil)
|
||||
@ -406,7 +406,7 @@ func (s *DockerSuite) TestContainerAPITopWindows(c *check.C) {
|
||||
Processes [][]string
|
||||
}
|
||||
var top topResp
|
||||
status, b, err := sockRequest("GET", "/containers/"+id+"/top", nil)
|
||||
status, b, err := request.SockRequest("GET", "/containers/"+id+"/top", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusOK)
|
||||
c.Assert(json.Unmarshal(b, &top), checker.IsNil)
|
||||
@ -434,7 +434,7 @@ func (s *DockerSuite) TestContainerAPICommit(c *check.C) {
|
||||
dockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test")
|
||||
|
||||
name := "testcontainerapicommit"
|
||||
status, b, err := sockRequest("POST", "/commit?repo="+name+"&testtag=tag&container="+cName, nil)
|
||||
status, b, err := request.SockRequest("POST", "/commit?repo="+name+"&testtag=tag&container="+cName, nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusCreated)
|
||||
|
||||
@ -460,7 +460,7 @@ func (s *DockerSuite) TestContainerAPICommitWithLabelInConfig(c *check.C) {
|
||||
}
|
||||
|
||||
name := "testcontainerapicommitwithconfig"
|
||||
status, b, err := sockRequest("POST", "/commit?repo="+name+"&container="+cName, config)
|
||||
status, b, err := request.SockRequest("POST", "/commit?repo="+name+"&container="+cName, config, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusCreated)
|
||||
|
||||
@ -502,7 +502,7 @@ func (s *DockerSuite) TestContainerAPIBadPort(c *check.C) {
|
||||
jsonData := bytes.NewBuffer(nil)
|
||||
json.NewEncoder(jsonData).Encode(config)
|
||||
|
||||
status, body, err := sockRequest("POST", "/containers/create", config)
|
||||
status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusInternalServerError)
|
||||
c.Assert(getErrorMessage(c, body), checker.Equals, `invalid port specification: "aa80"`, check.Commentf("Incorrect error msg: %s", body))
|
||||
@ -514,7 +514,7 @@ func (s *DockerSuite) TestContainerAPICreate(c *check.C) {
|
||||
"Cmd": []string{"/bin/sh", "-c", "touch /test && ls /test"},
|
||||
}
|
||||
|
||||
status, b, err := sockRequest("POST", "/containers/create", config)
|
||||
status, b, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusCreated)
|
||||
|
||||
@ -531,7 +531,7 @@ func (s *DockerSuite) TestContainerAPICreate(c *check.C) {
|
||||
func (s *DockerSuite) TestContainerAPICreateEmptyConfig(c *check.C) {
|
||||
config := map[string]interface{}{}
|
||||
|
||||
status, body, err := sockRequest("POST", "/containers/create", config)
|
||||
status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusInternalServerError)
|
||||
|
||||
@ -552,7 +552,7 @@ func (s *DockerSuite) TestContainerAPICreateMultipleNetworksConfig(c *check.C) {
|
||||
},
|
||||
}
|
||||
|
||||
status, body, err := sockRequest("POST", "/containers/create", config)
|
||||
status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusBadRequest)
|
||||
msg := getErrorMessage(c, body)
|
||||
@ -570,14 +570,14 @@ func (s *DockerSuite) TestContainerAPICreateWithHostName(c *check.C) {
|
||||
"Hostname": hostName,
|
||||
}
|
||||
|
||||
status, body, err := sockRequest("POST", "/containers/create", config)
|
||||
status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusCreated)
|
||||
|
||||
var container containertypes.ContainerCreateCreatedBody
|
||||
c.Assert(json.Unmarshal(body, &container), checker.IsNil)
|
||||
|
||||
status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
|
||||
status, body, err = request.SockRequest("GET", "/containers/"+container.ID+"/json", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusOK)
|
||||
|
||||
@ -593,14 +593,14 @@ func (s *DockerSuite) TestContainerAPICreateWithDomainName(c *check.C) {
|
||||
"Domainname": domainName,
|
||||
}
|
||||
|
||||
status, body, err := sockRequest("POST", "/containers/create", config)
|
||||
status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusCreated)
|
||||
|
||||
var container containertypes.ContainerCreateCreatedBody
|
||||
c.Assert(json.Unmarshal(body, &container), checker.IsNil)
|
||||
|
||||
status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
|
||||
status, body, err = request.SockRequest("GET", "/containers/"+container.ID+"/json", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusOK)
|
||||
|
||||
@ -628,14 +628,14 @@ func UtilCreateNetworkMode(c *check.C, networkMode string) {
|
||||
"HostConfig": map[string]interface{}{"NetworkMode": networkMode},
|
||||
}
|
||||
|
||||
status, body, err := sockRequest("POST", "/containers/create", config)
|
||||
status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusCreated)
|
||||
|
||||
var container containertypes.ContainerCreateCreatedBody
|
||||
c.Assert(json.Unmarshal(body, &container), checker.IsNil)
|
||||
|
||||
status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
|
||||
status, body, err = request.SockRequest("GET", "/containers/"+container.ID+"/json", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusOK)
|
||||
|
||||
@ -653,14 +653,14 @@ func (s *DockerSuite) TestContainerAPICreateWithCpuSharesCpuset(c *check.C) {
|
||||
"CpusetCpus": "0",
|
||||
}
|
||||
|
||||
status, body, err := sockRequest("POST", "/containers/create", config)
|
||||
status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusCreated)
|
||||
|
||||
var container containertypes.ContainerCreateCreatedBody
|
||||
c.Assert(json.Unmarshal(body, &container), checker.IsNil)
|
||||
|
||||
status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
|
||||
status, body, err = request.SockRequest("GET", "/containers/"+container.ID+"/json", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusOK)
|
||||
|
||||
@ -683,7 +683,7 @@ func (s *DockerSuite) TestContainerAPIVerifyHeader(c *check.C) {
|
||||
create := func(ct string) (*http.Response, io.ReadCloser, error) {
|
||||
jsonData := bytes.NewBuffer(nil)
|
||||
c.Assert(json.NewEncoder(jsonData).Encode(config), checker.IsNil)
|
||||
return sockRequestRaw("POST", "/containers/create", jsonData, ct)
|
||||
return request.SockRequestRaw("POST", "/containers/create", jsonData, ct, daemonHost())
|
||||
}
|
||||
|
||||
// Try with no content-type
|
||||
@ -719,7 +719,7 @@ func (s *DockerSuite) TestContainerAPIInvalidPortSyntax(c *check.C) {
|
||||
}
|
||||
}`
|
||||
|
||||
res, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
||||
res, body, err := request.SockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json", daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError)
|
||||
|
||||
@ -739,7 +739,7 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyInvalidPolicyName(c *check.C)
|
||||
}
|
||||
}`
|
||||
|
||||
res, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
||||
res, body, err := request.SockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json", daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError)
|
||||
|
||||
@ -759,7 +759,7 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyRetryMismatch(c *check.C) {
|
||||
}
|
||||
}`
|
||||
|
||||
res, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
||||
res, body, err := request.SockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json", daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError)
|
||||
|
||||
@ -779,7 +779,7 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyNegativeRetryCount(c *check.C
|
||||
}
|
||||
}`
|
||||
|
||||
res, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
||||
res, body, err := request.SockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json", daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError)
|
||||
|
||||
@ -799,7 +799,7 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyDefaultRetryCount(c *check.C)
|
||||
}
|
||||
}`
|
||||
|
||||
res, _, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
||||
res, _, err := request.SockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json", daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(res.StatusCode, checker.Equals, http.StatusCreated)
|
||||
}
|
||||
@ -830,7 +830,7 @@ func (s *DockerSuite) TestContainerAPIPostCreateNull(c *check.C) {
|
||||
"NetworkDisabled":false,
|
||||
"OnBuild":null}`
|
||||
|
||||
res, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
||||
res, body, err := request.SockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json", daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(res.StatusCode, checker.Equals, http.StatusCreated)
|
||||
|
||||
@ -861,7 +861,7 @@ func (s *DockerSuite) TestCreateWithTooLowMemoryLimit(c *check.C) {
|
||||
"Memory": 524287
|
||||
}`
|
||||
|
||||
res, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
||||
res, body, err := request.SockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json", daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
b, err2 := testutil.ReadBody(body)
|
||||
c.Assert(err2, checker.IsNil)
|
||||
@ -875,7 +875,7 @@ func (s *DockerSuite) TestContainerAPIRename(c *check.C) {
|
||||
|
||||
containerID := strings.TrimSpace(out)
|
||||
newName := "TestContainerAPIRenameNew"
|
||||
statusCode, _, err := sockRequest("POST", "/containers/"+containerID+"/rename?name="+newName, nil)
|
||||
statusCode, _, err := request.SockRequest("POST", "/containers/"+containerID+"/rename?name="+newName, nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
// 204 No Content is expected, not 200
|
||||
c.Assert(statusCode, checker.Equals, http.StatusNoContent)
|
||||
@ -888,7 +888,7 @@ func (s *DockerSuite) TestContainerAPIKill(c *check.C) {
|
||||
name := "test-api-kill"
|
||||
runSleepingContainer(c, "-i", "--name", name)
|
||||
|
||||
status, _, err := sockRequest("POST", "/containers/"+name+"/kill", nil)
|
||||
status, _, err := request.SockRequest("POST", "/containers/"+name+"/kill", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusNoContent)
|
||||
|
||||
@ -900,7 +900,7 @@ func (s *DockerSuite) TestContainerAPIRestart(c *check.C) {
|
||||
name := "test-api-restart"
|
||||
runSleepingContainer(c, "-di", "--name", name)
|
||||
|
||||
status, _, err := sockRequest("POST", "/containers/"+name+"/restart?t=1", nil)
|
||||
status, _, err := request.SockRequest("POST", "/containers/"+name+"/restart?t=1", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusNoContent)
|
||||
c.Assert(waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second), checker.IsNil)
|
||||
@ -912,7 +912,7 @@ func (s *DockerSuite) TestContainerAPIRestartNotimeoutParam(c *check.C) {
|
||||
id := strings.TrimSpace(out)
|
||||
c.Assert(waitRun(id), checker.IsNil)
|
||||
|
||||
status, _, err := sockRequest("POST", "/containers/"+name+"/restart", nil)
|
||||
status, _, err := request.SockRequest("POST", "/containers/"+name+"/restart", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusNoContent)
|
||||
c.Assert(waitInspect(name, "{{ .State.Restarting }} {{ .State.Running }}", "false true", 15*time.Second), checker.IsNil)
|
||||
@ -926,16 +926,16 @@ func (s *DockerSuite) TestContainerAPIStart(c *check.C) {
|
||||
"OpenStdin": true,
|
||||
}
|
||||
|
||||
status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
|
||||
status, _, err := request.SockRequest("POST", "/containers/create?name="+name, config, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusCreated)
|
||||
|
||||
status, _, err = sockRequest("POST", "/containers/"+name+"/start", nil)
|
||||
status, _, err = request.SockRequest("POST", "/containers/"+name+"/start", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusNoContent)
|
||||
|
||||
// second call to start should give 304
|
||||
status, _, err = sockRequest("POST", "/containers/"+name+"/start", nil)
|
||||
status, _, err = request.SockRequest("POST", "/containers/"+name+"/start", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
// TODO(tibor): figure out why this doesn't work on windows
|
||||
@ -948,13 +948,13 @@ func (s *DockerSuite) TestContainerAPIStop(c *check.C) {
|
||||
name := "test-api-stop"
|
||||
runSleepingContainer(c, "-i", "--name", name)
|
||||
|
||||
status, _, err := sockRequest("POST", "/containers/"+name+"/stop?t=30", nil)
|
||||
status, _, err := request.SockRequest("POST", "/containers/"+name+"/stop?t=30", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusNoContent)
|
||||
c.Assert(waitInspect(name, "{{ .State.Running }}", "false", 60*time.Second), checker.IsNil)
|
||||
|
||||
// second call to start should give 304
|
||||
status, _, err = sockRequest("POST", "/containers/"+name+"/stop?t=30", nil)
|
||||
status, _, err = request.SockRequest("POST", "/containers/"+name+"/stop?t=30", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusNotModified)
|
||||
}
|
||||
@ -968,7 +968,7 @@ func (s *DockerSuite) TestContainerAPIWait(c *check.C) {
|
||||
}
|
||||
dockerCmd(c, "run", "--name", name, "busybox", sleepCmd, "2")
|
||||
|
||||
status, body, err := sockRequest("POST", "/containers/"+name+"/wait", nil)
|
||||
status, body, err := request.SockRequest("POST", "/containers/"+name+"/wait", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusOK)
|
||||
c.Assert(waitInspect(name, "{{ .State.Running }}", "false", 60*time.Second), checker.IsNil)
|
||||
@ -986,7 +986,7 @@ func (s *DockerSuite) TestContainerAPICopyNotExistsAnyMore(c *check.C) {
|
||||
Resource: "/test.txt",
|
||||
}
|
||||
|
||||
status, _, err := sockRequest("POST", "/containers/"+name+"/copy", postData)
|
||||
status, _, err := request.SockRequest("POST", "/containers/"+name+"/copy", postData, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusNotFound)
|
||||
}
|
||||
@ -1000,7 +1000,7 @@ func (s *DockerSuite) TestContainerAPICopyPre124(c *check.C) {
|
||||
Resource: "/test.txt",
|
||||
}
|
||||
|
||||
status, body, err := sockRequest("POST", "/v1.23/containers/"+name+"/copy", postData)
|
||||
status, body, err := request.SockRequest("POST", "/v1.23/containers/"+name+"/copy", postData, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusOK)
|
||||
|
||||
@ -1030,7 +1030,7 @@ func (s *DockerSuite) TestContainerAPICopyResourcePathEmptyPr124(c *check.C) {
|
||||
Resource: "",
|
||||
}
|
||||
|
||||
status, body, err := sockRequest("POST", "/v1.23/containers/"+name+"/copy", postData)
|
||||
status, body, err := request.SockRequest("POST", "/v1.23/containers/"+name+"/copy", postData, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusInternalServerError)
|
||||
c.Assert(string(body), checker.Matches, "Path cannot be empty\n")
|
||||
@ -1045,7 +1045,7 @@ func (s *DockerSuite) TestContainerAPICopyResourcePathNotFoundPre124(c *check.C)
|
||||
Resource: "/notexist",
|
||||
}
|
||||
|
||||
status, body, err := sockRequest("POST", "/v1.23/containers/"+name+"/copy", postData)
|
||||
status, body, err := request.SockRequest("POST", "/v1.23/containers/"+name+"/copy", postData, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusInternalServerError)
|
||||
c.Assert(string(body), checker.Matches, "Could not find the file /notexist in container "+name+"\n")
|
||||
@ -1057,7 +1057,7 @@ func (s *DockerSuite) TestContainerAPICopyContainerNotFoundPr124(c *check.C) {
|
||||
Resource: "/something",
|
||||
}
|
||||
|
||||
status, _, err := sockRequest("POST", "/v1.23/containers/notexists/copy", postData)
|
||||
status, _, err := request.SockRequest("POST", "/v1.23/containers/notexists/copy", postData, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusNotFound)
|
||||
}
|
||||
@ -1070,13 +1070,13 @@ func (s *DockerSuite) TestContainerAPIDelete(c *check.C) {
|
||||
|
||||
dockerCmd(c, "stop", id)
|
||||
|
||||
status, _, err := sockRequest("DELETE", "/containers/"+id, nil)
|
||||
status, _, err := request.SockRequest("DELETE", "/containers/"+id, nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusNoContent)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIDeleteNotExist(c *check.C) {
|
||||
status, body, err := sockRequest("DELETE", "/containers/doesnotexist", nil)
|
||||
status, body, err := request.SockRequest("DELETE", "/containers/doesnotexist", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusNotFound)
|
||||
c.Assert(getErrorMessage(c, body), checker.Matches, "No such container: doesnotexist")
|
||||
@ -1088,7 +1088,7 @@ func (s *DockerSuite) TestContainerAPIDeleteForce(c *check.C) {
|
||||
id := strings.TrimSpace(out)
|
||||
c.Assert(waitRun(id), checker.IsNil)
|
||||
|
||||
status, _, err := sockRequest("DELETE", "/containers/"+id+"?force=1", nil)
|
||||
status, _, err := request.SockRequest("DELETE", "/containers/"+id+"?force=1", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusNoContent)
|
||||
}
|
||||
@ -1109,7 +1109,7 @@ func (s *DockerSuite) TestContainerAPIDeleteRemoveLinks(c *check.C) {
|
||||
links := inspectFieldJSON(c, id2, "HostConfig.Links")
|
||||
c.Assert(links, checker.Equals, "[\"/tlink1:/tlink2/tlink1\"]", check.Commentf("expected to have links between containers"))
|
||||
|
||||
status, b, err := sockRequest("DELETE", "/containers/tlink2/tlink1?link=1", nil)
|
||||
status, b, err := request.SockRequest("DELETE", "/containers/tlink2/tlink1?link=1", nil, daemonHost())
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusNoContent, check.Commentf(string(b)))
|
||||
|
||||
@ -1123,7 +1123,7 @@ func (s *DockerSuite) TestContainerAPIDeleteConflict(c *check.C) {
|
||||
id := strings.TrimSpace(out)
|
||||
c.Assert(waitRun(id), checker.IsNil)
|
||||
|
||||
status, _, err := sockRequest("DELETE", "/containers/"+id, nil)
|
||||
status, _, err := request.SockRequest("DELETE", "/containers/"+id, nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusConflict)
|
||||
}
|
||||
@ -1145,7 +1145,7 @@ func (s *DockerSuite) TestContainerAPIDeleteRemoveVolume(c *check.C) {
|
||||
_, err = os.Stat(source)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
status, _, err := sockRequest("DELETE", "/containers/"+id+"?v=1&force=1", nil)
|
||||
status, _, err := request.SockRequest("DELETE", "/containers/"+id+"?v=1&force=1", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusNoContent)
|
||||
_, err = os.Stat(source)
|
||||
@ -1154,30 +1154,21 @@ func (s *DockerSuite) TestContainerAPIDeleteRemoveVolume(c *check.C) {
|
||||
|
||||
// Regression test for https://github.com/docker/docker/issues/6231
|
||||
func (s *DockerSuite) TestContainerAPIChunkedEncoding(c *check.C) {
|
||||
conn, err := sockConn(time.Duration(10*time.Second), "")
|
||||
c.Assert(err, checker.IsNil)
|
||||
client := httputil.NewClientConn(conn, nil)
|
||||
defer client.Close()
|
||||
|
||||
config := map[string]interface{}{
|
||||
"Image": "busybox",
|
||||
"Cmd": append([]string{"/bin/sh", "-c"}, sleepCommandForDaemonPlatform()...),
|
||||
"OpenStdin": true,
|
||||
}
|
||||
b, err := json.Marshal(config)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
req, err := http.NewRequest("POST", "/containers/create", bytes.NewBuffer(b))
|
||||
c.Assert(err, checker.IsNil)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
// This is a cheat to make the http request do chunked encoding
|
||||
// Otherwise (just setting the Content-Encoding to chunked) net/http will overwrite
|
||||
// https://golang.org/src/pkg/net/http/request.go?s=11980:12172
|
||||
req.ContentLength = -1
|
||||
|
||||
resp, err := client.Do(req)
|
||||
resp, _, err := request.Post(daemonHost(), "/containers/create", request.JSONBody(config), func(req *http.Request) error {
|
||||
// This is a cheat to make the http request do chunked encoding
|
||||
// Otherwise (just setting the Content-Encoding to chunked) net/http will overwrite
|
||||
// https://golang.org/src/pkg/net/http/request.go?s=11980:12172
|
||||
req.ContentLength = -1
|
||||
return nil
|
||||
})
|
||||
c.Assert(err, checker.IsNil, check.Commentf("error creating container with chunked encoding"))
|
||||
resp.Body.Close()
|
||||
c.Assert(resp.StatusCode, checker.Equals, http.StatusCreated)
|
||||
}
|
||||
|
||||
@ -1187,7 +1178,7 @@ func (s *DockerSuite) TestContainerAPIPostContainerStop(c *check.C) {
|
||||
containerID := strings.TrimSpace(out)
|
||||
c.Assert(waitRun(containerID), checker.IsNil)
|
||||
|
||||
statusCode, _, err := sockRequest("POST", "/containers/"+containerID+"/stop", nil)
|
||||
statusCode, _, err := request.SockRequest("POST", "/containers/"+containerID+"/stop", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
// 204 No Content is expected, not 200
|
||||
c.Assert(statusCode, checker.Equals, http.StatusNoContent)
|
||||
@ -1201,7 +1192,7 @@ func (s *DockerSuite) TestPostContainerAPICreateWithStringOrSliceEntrypoint(c *c
|
||||
Entrypoint string
|
||||
Cmd []string
|
||||
}{"busybox", "echo", []string{"hello", "world"}}
|
||||
_, _, err := sockRequest("POST", "/containers/create?name=echotest", config)
|
||||
_, _, err := request.SockRequest("POST", "/containers/create?name=echotest", config, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
out, _ := dockerCmd(c, "start", "-a", "echotest")
|
||||
c.Assert(strings.TrimSpace(out), checker.Equals, "hello world")
|
||||
@ -1211,7 +1202,7 @@ func (s *DockerSuite) TestPostContainerAPICreateWithStringOrSliceEntrypoint(c *c
|
||||
Entrypoint []string
|
||||
Cmd []string
|
||||
}{"busybox", []string{"echo"}, []string{"hello", "world"}}
|
||||
_, _, err = sockRequest("POST", "/containers/create?name=echotest2", config2)
|
||||
_, _, err = request.SockRequest("POST", "/containers/create?name=echotest2", config2, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
out, _ = dockerCmd(c, "start", "-a", "echotest2")
|
||||
c.Assert(strings.TrimSpace(out), checker.Equals, "hello world")
|
||||
@ -1224,7 +1215,7 @@ func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCmd(c *check.C) {
|
||||
Entrypoint string
|
||||
Cmd string
|
||||
}{"busybox", "echo", "hello world"}
|
||||
_, _, err := sockRequest("POST", "/containers/create?name=echotest", config)
|
||||
_, _, err := request.SockRequest("POST", "/containers/create?name=echotest", config, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
out, _ := dockerCmd(c, "start", "-a", "echotest")
|
||||
c.Assert(strings.TrimSpace(out), checker.Equals, "hello world")
|
||||
@ -1233,7 +1224,7 @@ func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCmd(c *check.C) {
|
||||
Image string
|
||||
Cmd []string
|
||||
}{"busybox", []string{"echo", "hello", "world"}}
|
||||
_, _, err = sockRequest("POST", "/containers/create?name=echotest2", config2)
|
||||
_, _, err = request.SockRequest("POST", "/containers/create?name=echotest2", config2, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
out, _ = dockerCmd(c, "start", "-a", "echotest2")
|
||||
c.Assert(strings.TrimSpace(out), checker.Equals, "hello world")
|
||||
@ -1248,7 +1239,7 @@ func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCapAddDrop(c *che
|
||||
CapAdd string
|
||||
CapDrop string
|
||||
}{"busybox", "NET_ADMIN", "SYS_ADMIN"}
|
||||
status, _, err := sockRequest("POST", "/containers/create?name=capaddtest0", config)
|
||||
status, _, err := request.SockRequest("POST", "/containers/create?name=capaddtest0", config, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusCreated)
|
||||
|
||||
@ -1257,7 +1248,7 @@ func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCapAddDrop(c *che
|
||||
CapAdd []string
|
||||
CapDrop []string
|
||||
}{"busybox", []string{"NET_ADMIN", "SYS_ADMIN"}, []string{"SETGID"}}
|
||||
status, _, err = sockRequest("POST", "/containers/create?name=capaddtest1", config2)
|
||||
status, _, err = request.SockRequest("POST", "/containers/create?name=capaddtest1", config2, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusCreated)
|
||||
}
|
||||
@ -1268,7 +1259,7 @@ func (s *DockerSuite) TestContainerAPICreateNoHostConfig118(c *check.C) {
|
||||
config := struct {
|
||||
Image string
|
||||
}{"busybox"}
|
||||
status, _, err := sockRequest("POST", "/v1.18/containers/create", config)
|
||||
status, _, err := request.SockRequest("POST", "/v1.18/containers/create", config, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusCreated)
|
||||
}
|
||||
@ -1300,7 +1291,7 @@ func (s *DockerSuite) TestPutContainerArchiveErrSymlinkInVolumeToReadOnlyRootfs(
|
||||
query.Set("path", "/vol2/symlinkToAbsDir")
|
||||
urlPath := fmt.Sprintf("/v1.20/containers/%s/archive?%s", cID, query.Encode())
|
||||
|
||||
statusCode, body, err := sockRequest("PUT", urlPath, nil)
|
||||
statusCode, body, err := request.SockRequest("PUT", urlPath, nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
if !isCpCannotCopyReadOnly(fmt.Errorf(string(body))) {
|
||||
@ -1309,7 +1300,7 @@ func (s *DockerSuite) TestPutContainerArchiveErrSymlinkInVolumeToReadOnlyRootfs(
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestContainerAPIGetContainersJSONEmpty(c *check.C) {
|
||||
status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
|
||||
status, body, err := request.SockRequest("GET", "/containers/json?all=1", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusOK)
|
||||
c.Assert(string(body), checker.Equals, "[]\n")
|
||||
@ -1324,7 +1315,7 @@ func (s *DockerSuite) TestPostContainersCreateWithWrongCpusetValues(c *check.C)
|
||||
CpusetCpus string
|
||||
}{"busybox", "1-42,,"}
|
||||
name := "wrong-cpuset-cpus"
|
||||
status, body, err := sockRequest("POST", "/containers/create?name="+name, c1)
|
||||
status, body, err := request.SockRequest("POST", "/containers/create?name="+name, c1, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusInternalServerError)
|
||||
expected := "Invalid value 1-42,, for cpuset cpus"
|
||||
@ -1335,7 +1326,7 @@ func (s *DockerSuite) TestPostContainersCreateWithWrongCpusetValues(c *check.C)
|
||||
CpusetMems string
|
||||
}{"busybox", "42-3,1--"}
|
||||
name = "wrong-cpuset-mems"
|
||||
status, body, err = sockRequest("POST", "/containers/create?name="+name, c2)
|
||||
status, body, err = request.SockRequest("POST", "/containers/create?name="+name, c2, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusInternalServerError)
|
||||
expected = "Invalid value 42-3,1-- for cpuset mems"
|
||||
@ -1350,7 +1341,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeNegative(c *check.C) {
|
||||
"HostConfig": map[string]interface{}{"ShmSize": -1},
|
||||
}
|
||||
|
||||
status, body, err := sockRequest("POST", "/containers/create", config)
|
||||
status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
||||
c.Assert(getErrorMessage(c, body), checker.Contains, "SHM size can not be less than 0")
|
||||
@ -1365,14 +1356,14 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *check.
|
||||
"Cmd": "mount",
|
||||
}
|
||||
|
||||
status, body, err := sockRequest("POST", "/containers/create", config)
|
||||
status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusCreated)
|
||||
|
||||
var container containertypes.ContainerCreateCreatedBody
|
||||
c.Assert(json.Unmarshal(body, &container), check.IsNil)
|
||||
|
||||
status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
|
||||
status, body, err = request.SockRequest("GET", "/containers/"+container.ID+"/json", nil, daemonHost())
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusOK)
|
||||
|
||||
@ -1397,14 +1388,14 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeOmitted(c *check.C) {
|
||||
"Cmd": "mount",
|
||||
}
|
||||
|
||||
status, body, err := sockRequest("POST", "/containers/create", config)
|
||||
status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusCreated)
|
||||
|
||||
var container containertypes.ContainerCreateCreatedBody
|
||||
c.Assert(json.Unmarshal(body, &container), check.IsNil)
|
||||
|
||||
status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
|
||||
status, body, err = request.SockRequest("GET", "/containers/"+container.ID+"/json", nil, daemonHost())
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusOK)
|
||||
|
||||
@ -1429,14 +1420,14 @@ func (s *DockerSuite) TestPostContainersCreateWithShmSize(c *check.C) {
|
||||
"HostConfig": map[string]interface{}{"ShmSize": 1073741824},
|
||||
}
|
||||
|
||||
status, body, err := sockRequest("POST", "/containers/create", config)
|
||||
status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusCreated)
|
||||
|
||||
var container containertypes.ContainerCreateCreatedBody
|
||||
c.Assert(json.Unmarshal(body, &container), check.IsNil)
|
||||
|
||||
status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
|
||||
status, body, err = request.SockRequest("GET", "/containers/"+container.ID+"/json", nil, daemonHost())
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusOK)
|
||||
|
||||
@ -1459,14 +1450,14 @@ func (s *DockerSuite) TestPostContainersCreateMemorySwappinessHostConfigOmitted(
|
||||
"Image": "busybox",
|
||||
}
|
||||
|
||||
status, body, err := sockRequest("POST", "/containers/create", config)
|
||||
status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusCreated)
|
||||
|
||||
var container containertypes.ContainerCreateCreatedBody
|
||||
c.Assert(json.Unmarshal(body, &container), check.IsNil)
|
||||
|
||||
status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
|
||||
status, body, err = request.SockRequest("GET", "/containers/"+container.ID+"/json", nil, daemonHost())
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusOK)
|
||||
|
||||
@ -1486,7 +1477,7 @@ func (s *DockerSuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *che
|
||||
OomScoreAdj int
|
||||
}{"busybox", 1001}
|
||||
name := "oomscoreadj-over"
|
||||
status, b, err := sockRequest("POST", "/containers/create?name="+name, config)
|
||||
status, b, err := request.SockRequest("POST", "/containers/create?name="+name, config, daemonHost())
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
||||
|
||||
@ -1501,7 +1492,7 @@ func (s *DockerSuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *che
|
||||
OomScoreAdj int
|
||||
}{"busybox", -1001}
|
||||
name = "oomscoreadj-low"
|
||||
status, b, err = sockRequest("POST", "/containers/create?name="+name, config)
|
||||
status, b, err = request.SockRequest("POST", "/containers/create?name="+name, config, daemonHost())
|
||||
c.Assert(err, check.IsNil)
|
||||
c.Assert(status, check.Equals, http.StatusInternalServerError)
|
||||
expected = "Invalid value -1001, range for oom score adj is [-1000, 1000]"
|
||||
@ -1513,7 +1504,7 @@ func (s *DockerSuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *che
|
||||
|
||||
// test case for #22210 where an empty container name caused panic.
|
||||
func (s *DockerSuite) TestContainerAPIDeleteWithEmptyName(c *check.C) {
|
||||
status, out, err := sockRequest("DELETE", "/containers/", nil)
|
||||
status, out, err := request.SockRequest("DELETE", "/containers/", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusBadRequest)
|
||||
c.Assert(string(out), checker.Contains, "No container name or ID supplied")
|
||||
@ -1530,11 +1521,11 @@ func (s *DockerSuite) TestContainerAPIStatsWithNetworkDisabled(c *check.C) {
|
||||
"NetworkDisabled": true,
|
||||
}
|
||||
|
||||
status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
|
||||
status, _, err := request.SockRequest("POST", "/containers/create?name="+name, config, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusCreated)
|
||||
|
||||
status, _, err = sockRequest("POST", "/containers/"+name+"/start", nil)
|
||||
status, _, err = request.SockRequest("POST", "/containers/"+name+"/start", nil, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, http.StatusNoContent)
|
||||
|
||||
@ -1547,7 +1538,7 @@ func (s *DockerSuite) TestContainerAPIStatsWithNetworkDisabled(c *check.C) {
|
||||
}
|
||||
bc := make(chan b, 1)
|
||||
go func() {
|
||||
status, body, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
|
||||
status, body, err := request.SockRequest("GET", "/containers/"+name+"/stats", nil, daemonHost())
|
||||
bc <- b{status, body, err}
|
||||
}()
|
||||
|
||||
@ -1755,7 +1746,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *check.C) {
|
||||
|
||||
for i, x := range cases {
|
||||
c.Logf("case %d", i)
|
||||
status, b, err := sockRequest("POST", "/containers/create", x.config)
|
||||
status, b, err := request.SockRequest("POST", "/containers/create", x.config, daemonHost())
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(status, checker.Equals, x.status, check.Commentf("%s\n%v", string(b), cases[i].config))
|
||||
if len(x.msg) > 0 {
|
||||
@ -1780,7 +1771,7 @@ func (s *DockerSuite) TestContainerAPICreateMountsBindRead(c *check.C) {
|
||||
"Cmd": []string{"/bin/sh", "-c", "cat /foo/bar"},
|
||||
"HostConfig": map[string]interface{}{"Mounts": []map[string]interface{}{{"Type": "bind", "Source": tmpDir, "Target": destPath}}},
|
||||
}
|
||||
status, resp, err := sockRequest("POST", "/containers/create?name=test", data)
|
||||
status, resp, err := request.SockRequest("POST", "/containers/create?name=test", data, daemonHost())
|
||||
c.Assert(err, checker.IsNil, check.Commentf(string(resp)))
|
||||
c.Assert(status, checker.Equals, http.StatusCreated, check.Commentf(string(resp)))
|
||||
|
||||
@ -1868,7 +1859,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *check.C) {
|
||||
}
|
||||
for i, x := range cases {
|
||||
c.Logf("case %d - config: %v", i, x.cfg)
|
||||
status, data, err := sockRequest("POST", "/containers/create", wrapper{containertypes.Config{Image: testImg}, containertypes.HostConfig{Mounts: []mounttypes.Mount{x.cfg}}})
|
||||
status, data, err := request.SockRequest("POST", "/containers/create", wrapper{containertypes.Config{Image: testImg}, containertypes.HostConfig{Mounts: []mounttypes.Mount{x.cfg}}}, daemonHost())
|
||||
c.Assert(err, checker.IsNil, check.Commentf(string(data)))
|
||||
c.Assert(status, checker.Equals, http.StatusCreated, check.Commentf(string(data)))
|
||||
|
||||
@ -1950,7 +1941,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsTmpfs(c *check.C) {
|
||||
fmt.Sprintf("mount | grep 'tmpfs on %s'", target)},
|
||||
"HostConfig": map[string]interface{}{"Mounts": []map[string]interface{}{x.cfg}},
|
||||
}
|
||||
status, resp, err := sockRequest("POST", "/containers/create?name="+cName, data)
|
||||
status, resp, err := request.SockRequest("POST", "/containers/create?name="+cName, data, daemonHost())
|
||||
c.Assert(err, checker.IsNil, check.Commentf(string(resp)))
|
||||
c.Assert(status, checker.Equals, http.StatusCreated, check.Commentf(string(resp)))
|
||||
out, _ := dockerCmd(c, "start", "-a", cName)
|
||||
|
Reference in New Issue
Block a user