1
0
mirror of https://github.com/moby/moby.git synced 2025-07-29 07:21:35 +03:00

Update request.* signature to remove the host

99.9% of use case for request call are using daemonHost. This makes it
default and adds a `request.DoOnHost` function to be able to specify
the host for specific, more complex use cases.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester
2017-03-06 16:35:27 +01:00
parent 3cfc3e30a8
commit b11ba1231e
17 changed files with 96 additions and 93 deletions

View File

@ -216,7 +216,7 @@ func (s *DockerSuite) TestGetContainerStatsRmRunning(c *check.C) {
buf := &testutil.ChannelBuffer{C: make(chan []byte, 1)}
defer buf.Close()
_, body, err := request.Get(daemonHost(), "/containers/"+id+"/stats?stream=1", request.JSON)
_, body, err := request.Get("/containers/"+id+"/stats?stream=1", request.JSON)
c.Assert(err, checker.IsNil)
defer body.Close()
@ -255,7 +255,7 @@ func (s *DockerSuite) TestGetContainerStatsStream(c *check.C) {
}
bc := make(chan b, 1)
go func() {
status, body, err := request.Get(daemonHost(), "/containers/"+name+"/stats")
status, body, err := request.Get("/containers/" + name + "/stats")
bc <- b{status.StatusCode, 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 := request.Get(daemonHost(), "/containers/"+name+"/stats")
resp, body, err := request.Get("/containers/" + name + "/stats")
body.Close()
chResp <- stats{resp.StatusCode, err}
}()
@ -661,7 +661,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 request.Post(daemonHost(), "/containers/create", request.RawContent(ioutil.NopCloser(jsonData)), request.ContentType(ct))
return request.Post("/containers/create", request.RawContent(ioutil.NopCloser(jsonData)), request.ContentType(ct))
}
// Try with no content-type
@ -697,7 +697,7 @@ func (s *DockerSuite) TestContainerAPIInvalidPortSyntax(c *check.C) {
}
}`
res, body, err := request.Post(daemonHost(), "/containers/create", request.RawString(config), request.JSON)
res, body, err := request.Post("/containers/create", request.RawString(config), request.JSON)
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError)
@ -717,7 +717,7 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyInvalidPolicyName(c *check.C)
}
}`
res, body, err := request.Post(daemonHost(), "/containers/create", request.RawString(config), request.JSON)
res, body, err := request.Post("/containers/create", request.RawString(config), request.JSON)
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError)
@ -737,7 +737,7 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyRetryMismatch(c *check.C) {
}
}`
res, body, err := request.Post(daemonHost(), "/containers/create", request.RawString(config), request.JSON)
res, body, err := request.Post("/containers/create", request.RawString(config), request.JSON)
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError)
@ -757,7 +757,7 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyNegativeRetryCount(c *check.C
}
}`
res, body, err := request.Post(daemonHost(), "/containers/create", request.RawString(config), request.JSON)
res, body, err := request.Post("/containers/create", request.RawString(config), request.JSON)
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError)
@ -777,7 +777,7 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyDefaultRetryCount(c *check.C)
}
}`
res, _, err := request.Post(daemonHost(), "/containers/create", request.RawString(config), request.JSON)
res, _, err := request.Post("/containers/create", request.RawString(config), request.JSON)
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusCreated)
}
@ -808,7 +808,7 @@ func (s *DockerSuite) TestContainerAPIPostCreateNull(c *check.C) {
"NetworkDisabled":false,
"OnBuild":null}`
res, body, err := request.Post(daemonHost(), "/containers/create", request.RawString(config), request.JSON)
res, body, err := request.Post("/containers/create", request.RawString(config), request.JSON)
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusCreated)
@ -839,7 +839,7 @@ func (s *DockerSuite) TestCreateWithTooLowMemoryLimit(c *check.C) {
"Memory": 524287
}`
res, body, err := request.Post(daemonHost(), "/containers/create", request.RawString(config), request.JSON)
res, body, err := request.Post("/containers/create", request.RawString(config), request.JSON)
c.Assert(err, checker.IsNil)
b, err2 := testutil.ReadBody(body)
c.Assert(err2, checker.IsNil)
@ -1139,7 +1139,7 @@ func (s *DockerSuite) TestContainerAPIChunkedEncoding(c *check.C) {
"OpenStdin": true,
}
resp, _, err := request.Post(daemonHost(), "/containers/create", request.JSONBody(config), func(req *http.Request) error {
resp, _, err := request.Post("/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