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

@@ -18,13 +18,13 @@ import (
)
func (s *DockerSuite) TestAPIOptionsRoute(c *check.C) {
resp, _, err := request.Do(daemonHost(), "/", request.Method(http.MethodOptions))
resp, _, err := request.Do("/", request.Method(http.MethodOptions))
c.Assert(err, checker.IsNil)
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
}
func (s *DockerSuite) TestAPIGetEnabledCORS(c *check.C) {
res, body, err := request.Get(daemonHost(), "/version")
res, body, err := request.Get("/version")
c.Assert(err, checker.IsNil)
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
body.Close()
@@ -49,7 +49,7 @@ func (s *DockerSuite) TestAPIClientVersionOldNotSupported(c *check.C) {
v[1] = strconv.Itoa(vMinInt)
version := strings.Join(v, ".")
resp, body, err := request.Get(daemonHost(), "/v"+version+"/version")
resp, body, err := request.Get("/v" + version + "/version")
c.Assert(err, checker.IsNil)
defer body.Close()
c.Assert(resp.StatusCode, checker.Equals, http.StatusBadRequest)
@@ -80,7 +80,7 @@ func (s *DockerSuite) TestAPIDockerAPIVersion(c *check.C) {
}
func (s *DockerSuite) TestAPIErrorJSON(c *check.C) {
httpResp, body, err := request.Post(daemonHost(), "/containers/create", request.JSONBody(struct{}{}))
httpResp, body, err := request.Post("/containers/create", request.JSONBody(struct{}{}))
c.Assert(err, checker.IsNil)
c.Assert(httpResp.StatusCode, checker.Equals, http.StatusInternalServerError)
c.Assert(httpResp.Header.Get("Content-Type"), checker.Equals, "application/json")
@@ -93,7 +93,7 @@ func (s *DockerSuite) TestAPIErrorPlainText(c *check.C) {
// Windows requires API 1.25 or later. This test is validating a behaviour which was present
// in v1.23, but changed in 1.24, hence not applicable on Windows. See apiVersionSupportsJSONErrors
testRequires(c, DaemonIsLinux)
httpResp, body, err := request.Post(daemonHost(), "/v1.23/containers/create", request.JSONBody(struct{}{}))
httpResp, body, err := request.Post("/v1.23/containers/create", request.JSONBody(struct{}{}))
c.Assert(err, checker.IsNil)
c.Assert(httpResp.StatusCode, checker.Equals, http.StatusInternalServerError)
c.Assert(httpResp.Header.Get("Content-Type"), checker.Contains, "text/plain")
@@ -104,7 +104,7 @@ func (s *DockerSuite) TestAPIErrorPlainText(c *check.C) {
func (s *DockerSuite) TestAPIErrorNotFoundJSON(c *check.C) {
// 404 is a different code path to normal errors, so test separately
httpResp, body, err := request.Get(daemonHost(), "/notfound", request.JSON)
httpResp, body, err := request.Get("/notfound", request.JSON)
c.Assert(err, checker.IsNil)
c.Assert(httpResp.StatusCode, checker.Equals, http.StatusNotFound)
c.Assert(httpResp.Header.Get("Content-Type"), checker.Equals, "application/json")
@@ -114,7 +114,7 @@ func (s *DockerSuite) TestAPIErrorNotFoundJSON(c *check.C) {
}
func (s *DockerSuite) TestAPIErrorNotFoundPlainText(c *check.C) {
httpResp, body, err := request.Get(daemonHost(), "/v1.23/notfound", request.JSON)
httpResp, body, err := request.Get("/v1.23/notfound", request.JSON)
c.Assert(err, checker.IsNil)
c.Assert(httpResp.StatusCode, checker.Equals, http.StatusNotFound)
c.Assert(httpResp.Header.Get("Content-Type"), checker.Contains, "text/plain")