mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05: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:
parent
3cfc3e30a8
commit
b11ba1231e
17 changed files with 96 additions and 93 deletions
|
@ -718,7 +718,7 @@ func (d *Daemon) ReloadConfig() error {
|
||||||
errCh := make(chan error)
|
errCh := make(chan error)
|
||||||
started := make(chan struct{})
|
started := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
_, body, err := request.Get(d.Sock(), "/events")
|
_, body, err := request.DoOnHost(d.Sock(), "/events", request.Method(http.MethodGet))
|
||||||
close(started)
|
close(started)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errCh <- err
|
errCh <- err
|
||||||
|
|
|
@ -32,7 +32,7 @@ RUN find /tmp/`
|
||||||
server := fakeStorage(c, map[string]string{"testD": testD})
|
server := fakeStorage(c, map[string]string{"testD": testD})
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
|
||||||
res, body, err := request.Post(daemonHost(), "/build?dockerfile=baz&remote="+server.URL()+"/testD", request.JSON)
|
res, body, err := request.Post("/build?dockerfile=baz&remote="+server.URL()+"/testD", request.JSON)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ func (s *DockerSuite) TestBuildAPIRemoteTarballContext(c *check.C) {
|
||||||
})
|
})
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
|
||||||
res, b, err := request.Post(daemonHost(), "/build?remote="+server.URL()+"/testT.tar", request.ContentType("application/tar"))
|
res, b, err := request.Post("/build?remote="+server.URL()+"/testT.tar", request.ContentType("application/tar"))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||||
b.Close()
|
b.Close()
|
||||||
|
@ -119,7 +119,7 @@ RUN echo 'right'
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
|
||||||
url := "/build?dockerfile=custom&remote=" + server.URL() + "/testT.tar"
|
url := "/build?dockerfile=custom&remote=" + server.URL() + "/testT.tar"
|
||||||
res, body, err := request.Post(daemonHost(), url, request.ContentType("application/tar"))
|
res, body, err := request.Post(url, request.ContentType("application/tar"))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ RUN echo from dockerfile`,
|
||||||
}, false)
|
}, false)
|
||||||
defer git.Close()
|
defer git.Close()
|
||||||
|
|
||||||
res, body, err := request.Post(daemonHost(), "/build?remote="+git.RepoURL, request.JSON)
|
res, body, err := request.Post("/build?remote="+git.RepoURL, request.JSON)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ RUN echo from Dockerfile`,
|
||||||
defer git.Close()
|
defer git.Close()
|
||||||
|
|
||||||
// Make sure it tries to 'dockerfile' query param value
|
// Make sure it tries to 'dockerfile' query param value
|
||||||
res, body, err := request.Post(daemonHost(), "/build?dockerfile=baz&remote="+git.RepoURL, request.JSON)
|
res, body, err := request.Post("/build?dockerfile=baz&remote="+git.RepoURL, request.JSON)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ RUN echo from dockerfile`,
|
||||||
defer git.Close()
|
defer git.Close()
|
||||||
|
|
||||||
// Make sure it tries to 'dockerfile' query param value
|
// Make sure it tries to 'dockerfile' query param value
|
||||||
res, body, err := request.Post(daemonHost(), "/build?remote="+git.RepoURL, request.JSON)
|
res, body, err := request.Post("/build?remote="+git.RepoURL, request.JSON)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ func (s *DockerSuite) TestBuildAPIUnnormalizedTarPaths(c *check.C) {
|
||||||
// failed to close tar archive
|
// failed to close tar archive
|
||||||
c.Assert(tw.Close(), checker.IsNil)
|
c.Assert(tw.Close(), checker.IsNil)
|
||||||
|
|
||||||
res, body, err := request.Post(daemonHost(), "/build", request.RawContent(ioutil.NopCloser(buffer)), request.ContentType("application/x-tar"))
|
res, body, err := request.Post("/build", request.RawContent(ioutil.NopCloser(buffer)), request.ContentType("application/x-tar"))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||||
|
|
||||||
|
|
|
@ -216,7 +216,7 @@ func (s *DockerSuite) TestGetContainerStatsRmRunning(c *check.C) {
|
||||||
buf := &testutil.ChannelBuffer{C: make(chan []byte, 1)}
|
buf := &testutil.ChannelBuffer{C: make(chan []byte, 1)}
|
||||||
defer buf.Close()
|
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)
|
c.Assert(err, checker.IsNil)
|
||||||
defer body.Close()
|
defer body.Close()
|
||||||
|
|
||||||
|
@ -255,7 +255,7 @@ func (s *DockerSuite) TestGetContainerStatsStream(c *check.C) {
|
||||||
}
|
}
|
||||||
bc := make(chan b, 1)
|
bc := make(chan b, 1)
|
||||||
go func() {
|
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}
|
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
|
// 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.
|
// below we'll check this on a timeout.
|
||||||
go func() {
|
go func() {
|
||||||
resp, body, err := request.Get(daemonHost(), "/containers/"+name+"/stats")
|
resp, body, err := request.Get("/containers/" + name + "/stats")
|
||||||
body.Close()
|
body.Close()
|
||||||
chResp <- stats{resp.StatusCode, err}
|
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) {
|
create := func(ct string) (*http.Response, io.ReadCloser, error) {
|
||||||
jsonData := bytes.NewBuffer(nil)
|
jsonData := bytes.NewBuffer(nil)
|
||||||
c.Assert(json.NewEncoder(jsonData).Encode(config), checker.IsNil)
|
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
|
// 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(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError)
|
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(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError)
|
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(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError)
|
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(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError)
|
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(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusCreated)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusCreated)
|
||||||
}
|
}
|
||||||
|
@ -808,7 +808,7 @@ func (s *DockerSuite) TestContainerAPIPostCreateNull(c *check.C) {
|
||||||
"NetworkDisabled":false,
|
"NetworkDisabled":false,
|
||||||
"OnBuild":null}`
|
"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(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusCreated)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusCreated)
|
||||||
|
|
||||||
|
@ -839,7 +839,7 @@ func (s *DockerSuite) TestCreateWithTooLowMemoryLimit(c *check.C) {
|
||||||
"Memory": 524287
|
"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)
|
c.Assert(err, checker.IsNil)
|
||||||
b, err2 := testutil.ReadBody(body)
|
b, err2 := testutil.ReadBody(body)
|
||||||
c.Assert(err2, checker.IsNil)
|
c.Assert(err2, checker.IsNil)
|
||||||
|
@ -1139,7 +1139,7 @@ func (s *DockerSuite) TestContainerAPIChunkedEncoding(c *check.C) {
|
||||||
"OpenStdin": true,
|
"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
|
// This is a cheat to make the http request do chunked encoding
|
||||||
// Otherwise (just setting the Content-Encoding to chunked) net/http will overwrite
|
// Otherwise (just setting the Content-Encoding to chunked) net/http will overwrite
|
||||||
// https://golang.org/src/pkg/net/http/request.go?s=11980:12172
|
// https://golang.org/src/pkg/net/http/request.go?s=11980:12172
|
||||||
|
|
|
@ -22,7 +22,7 @@ func (s *DockerSuite) TestEventsAPIEmptyOutput(c *check.C) {
|
||||||
}
|
}
|
||||||
chResp := make(chan *apiResp)
|
chResp := make(chan *apiResp)
|
||||||
go func() {
|
go func() {
|
||||||
resp, body, err := request.Get(daemonHost(), "/events")
|
resp, body, err := request.Get("/events")
|
||||||
body.Close()
|
body.Close()
|
||||||
chResp <- &apiResp{resp, err}
|
chResp <- &apiResp{resp, err}
|
||||||
}()
|
}()
|
||||||
|
@ -47,7 +47,7 @@ func (s *DockerSuite) TestEventsAPIBackwardsCompatible(c *check.C) {
|
||||||
q := url.Values{}
|
q := url.Values{}
|
||||||
q.Set("since", ts)
|
q.Set("since", ts)
|
||||||
|
|
||||||
_, body, err := request.Get(daemonHost(), "/events?"+q.Encode())
|
_, body, err := request.Get("/events?" + q.Encode())
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
defer body.Close()
|
defer body.Close()
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ func (s *DockerSuite) TestExecResizeImmediatelyAfterExecStart(c *check.C) {
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
_, rc, err := request.Post(daemonHost(), fmt.Sprintf("/exec/%s/resize?h=24&w=80", execID), request.ContentType("text/plain"))
|
_, rc, err := request.Post(fmt.Sprintf("/exec/%s/resize?h=24&w=80", execID), request.ContentType("text/plain"))
|
||||||
// It's probably a panic of the daemon if io.ErrUnexpectedEOF is returned.
|
// It's probably a panic of the daemon if io.ErrUnexpectedEOF is returned.
|
||||||
if err == io.ErrUnexpectedEOF {
|
if err == io.ErrUnexpectedEOF {
|
||||||
return fmt.Errorf("The daemon might have crashed.")
|
return fmt.Errorf("The daemon might have crashed.")
|
||||||
|
|
|
@ -38,7 +38,7 @@ func (s *DockerSuite) TestExecAPICreateNoValidContentType(c *check.C) {
|
||||||
c.Fatalf("Can not encode data to json %s", err)
|
c.Fatalf("Can not encode data to json %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
res, body, err := request.Post(daemonHost(), fmt.Sprintf("/containers/%s/exec", name), request.RawContent(ioutil.NopCloser(jsonData)), request.ContentType("test/plain"))
|
res, body, err := request.Post(fmt.Sprintf("/containers/%s/exec", name), request.RawContent(ioutil.NopCloser(jsonData)), request.ContentType("test/plain"))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError)
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ func (s *DockerSuite) TestExecAPIStartEnsureHeaders(c *check.C) {
|
||||||
dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top")
|
dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top")
|
||||||
|
|
||||||
id := createExec(c, "test")
|
id := createExec(c, "test")
|
||||||
resp, _, err := request.Post(daemonHost(), fmt.Sprintf("/exec/%s/start", id), request.RawString(`{"Detach": true}`), request.JSON)
|
resp, _, err := request.Post(fmt.Sprintf("/exec/%s/start", id), request.RawString(`{"Detach": true}`), request.JSON)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(resp.Header.Get("Server"), checker.Not(checker.Equals), "")
|
c.Assert(resp.Header.Get("Server"), checker.Not(checker.Equals), "")
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ func (s *DockerSuite) TestExecAPIStartBackwardsCompatible(c *check.C) {
|
||||||
runSleepingContainer(c, "-d", "--name", "test")
|
runSleepingContainer(c, "-d", "--name", "test")
|
||||||
id := createExec(c, "test")
|
id := createExec(c, "test")
|
||||||
|
|
||||||
resp, body, err := request.Post(daemonHost(), fmt.Sprintf("/v1.20/exec/%s/start", id), request.RawString(`{"Detach": true}`), request.ContentType("text/plain"))
|
resp, body, err := request.Post(fmt.Sprintf("/v1.20/exec/%s/start", id), request.RawString(`{"Detach": true}`), request.ContentType("text/plain"))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
b, err := testutil.ReadBody(body)
|
b, err := testutil.ReadBody(body)
|
||||||
|
@ -141,14 +141,14 @@ func (s *DockerSuite) TestExecAPIStartWithDetach(c *check.C) {
|
||||||
}{}
|
}{}
|
||||||
c.Assert(json.Unmarshal(b, &createResp), checker.IsNil, check.Commentf(string(b)))
|
c.Assert(json.Unmarshal(b, &createResp), checker.IsNil, check.Commentf(string(b)))
|
||||||
|
|
||||||
_, body, err := request.Post(daemonHost(), fmt.Sprintf("/exec/%s/start", createResp.ID), request.RawString(`{"Detach": true}`), request.JSON)
|
_, body, err := request.Post(fmt.Sprintf("/exec/%s/start", createResp.ID), request.RawString(`{"Detach": true}`), request.JSON)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
b, err = testutil.ReadBody(body)
|
b, err = testutil.ReadBody(body)
|
||||||
comment := check.Commentf("response body: %s", b)
|
comment := check.Commentf("response body: %s", b)
|
||||||
c.Assert(err, checker.IsNil, comment)
|
c.Assert(err, checker.IsNil, comment)
|
||||||
|
|
||||||
resp, _, err := request.Get(daemonHost(), "/_ping")
|
resp, _, err := request.Get("/_ping")
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
c.Fatal("daemon is down, it should alive")
|
c.Fatal("daemon is down, it should alive")
|
||||||
|
@ -191,7 +191,7 @@ func createExec(c *check.C, name string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func createExecCmd(c *check.C, name string, cmd string) string {
|
func createExecCmd(c *check.C, name string, cmd string) string {
|
||||||
_, reader, err := request.Post(daemonHost(), fmt.Sprintf("/containers/%s/exec", name), request.JSONBody(map[string]interface{}{"Cmd": []string{cmd}}))
|
_, reader, err := request.Post(fmt.Sprintf("/containers/%s/exec", name), request.JSONBody(map[string]interface{}{"Cmd": []string{cmd}}))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
b, err := ioutil.ReadAll(reader)
|
b, err := ioutil.ReadAll(reader)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
@ -204,7 +204,7 @@ func createExecCmd(c *check.C, name string, cmd string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func startExec(c *check.C, id string, code int) {
|
func startExec(c *check.C, id string, code int) {
|
||||||
resp, body, err := request.Post(daemonHost(), fmt.Sprintf("/exec/%s/start", id), request.RawString(`{"Detach": true}`), request.JSON)
|
resp, body, err := request.Post(fmt.Sprintf("/exec/%s/start", id), request.RawString(`{"Detach": true}`), request.JSON)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
b, err := testutil.ReadBody(body)
|
b, err := testutil.ReadBody(body)
|
||||||
|
@ -214,7 +214,7 @@ func startExec(c *check.C, id string, code int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func inspectExec(c *check.C, id string, out interface{}) {
|
func inspectExec(c *check.C, id string, out interface{}) {
|
||||||
resp, body, err := request.Get(daemonHost(), fmt.Sprintf("/exec/%s/json", id))
|
resp, body, err := request.Get(fmt.Sprintf("/exec/%s/json", id))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
defer body.Close()
|
defer body.Close()
|
||||||
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
||||||
|
@ -240,7 +240,7 @@ func waitForExec(c *check.C, id string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func inspectContainer(c *check.C, id string, out interface{}) {
|
func inspectContainer(c *check.C, id string, out interface{}) {
|
||||||
resp, body, err := request.Get(daemonHost(), fmt.Sprintf("/containers/%s/json", id))
|
resp, body, err := request.Get(fmt.Sprintf("/containers/%s/json", id))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
defer body.Close()
|
defer body.Close()
|
||||||
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
||||||
|
|
|
@ -56,14 +56,14 @@ func (s *DockerSuite) TestAPIImagesSaveAndLoad(c *check.C) {
|
||||||
buildImageSuccessfully(c, "saveandload", withDockerfile("FROM busybox\nENV FOO bar"))
|
buildImageSuccessfully(c, "saveandload", withDockerfile("FROM busybox\nENV FOO bar"))
|
||||||
id := getIDByName(c, "saveandload")
|
id := getIDByName(c, "saveandload")
|
||||||
|
|
||||||
res, body, err := request.Get(daemonHost(), "/images/"+id+"/get")
|
res, body, err := request.Get("/images/" + id + "/get")
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
defer body.Close()
|
defer body.Close()
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||||
|
|
||||||
dockerCmd(c, "rmi", id)
|
dockerCmd(c, "rmi", id)
|
||||||
|
|
||||||
res, loadBody, err := request.Post(daemonHost(), "/images/load", request.RawContent(body), request.ContentType("application/x-tar"))
|
res, loadBody, err := request.Post("/images/load", request.RawContent(body), request.ContentType("application/x-tar"))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
defer loadBody.Close()
|
defer loadBody.Close()
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||||
|
@ -119,7 +119,7 @@ func (s *DockerSuite) TestAPIImagesHistory(c *check.C) {
|
||||||
func (s *DockerSuite) TestAPIImagesSearchJSONContentType(c *check.C) {
|
func (s *DockerSuite) TestAPIImagesSearchJSONContentType(c *check.C) {
|
||||||
testRequires(c, Network)
|
testRequires(c, Network)
|
||||||
|
|
||||||
res, b, err := request.Get(daemonHost(), "/images/search?term=test", request.JSON)
|
res, b, err := request.Get("/images/search?term=test", request.JSON)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
b.Close()
|
b.Close()
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||||
|
|
|
@ -25,7 +25,7 @@ func (s *DockerSuite) TestLogsAPIWithStdout(c *check.C) {
|
||||||
chLog := make(chan logOut)
|
chLog := make(chan logOut)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
res, body, err := request.Get(daemonHost(), fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1×tamps=1", id))
|
res, body, err := request.Get(fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1×tamps=1", id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
chLog <- logOut{"", nil, err}
|
chLog <- logOut{"", nil, err}
|
||||||
return
|
return
|
||||||
|
@ -69,7 +69,7 @@ func (s *DockerSuite) TestLogsAPIFollowEmptyOutput(c *check.C) {
|
||||||
t0 := time.Now()
|
t0 := time.Now()
|
||||||
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "sleep", "10")
|
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "sleep", "10")
|
||||||
|
|
||||||
_, body, err := request.Get(daemonHost(), fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name))
|
_, body, err := request.Get(fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name))
|
||||||
t1 := time.Now()
|
t1 := time.Now()
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
body.Close()
|
body.Close()
|
||||||
|
@ -81,7 +81,7 @@ func (s *DockerSuite) TestLogsAPIFollowEmptyOutput(c *check.C) {
|
||||||
|
|
||||||
func (s *DockerSuite) TestLogsAPIContainerNotFound(c *check.C) {
|
func (s *DockerSuite) TestLogsAPIContainerNotFound(c *check.C) {
|
||||||
name := "nonExistentContainer"
|
name := "nonExistentContainer"
|
||||||
resp, _, err := request.Get(daemonHost(), fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name))
|
resp, _, err := request.Get(fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(resp.StatusCode, checker.Equals, http.StatusNotFound)
|
c.Assert(resp.StatusCode, checker.Equals, http.StatusNotFound)
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,7 +257,7 @@ func createDeletePredefinedNetwork(c *check.C, name string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func isNetworkAvailable(c *check.C, name string) bool {
|
func isNetworkAvailable(c *check.C, name string) bool {
|
||||||
resp, body, err := request.Get(daemonHost(), "/networks")
|
resp, body, err := request.Get("/networks")
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
||||||
|
@ -284,7 +284,7 @@ func getNetworkIDByName(c *check.C, name string) string {
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
v.Set("filters", filterJSON)
|
v.Set("filters", filterJSON)
|
||||||
|
|
||||||
resp, body, err := request.Get(daemonHost(), "/networks?"+v.Encode())
|
resp, body, err := request.Get("/networks?" + v.Encode())
|
||||||
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ func getNetworkIDByName(c *check.C, name string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getNetworkResource(c *check.C, id string) *types.NetworkResource {
|
func getNetworkResource(c *check.C, id string) *types.NetworkResource {
|
||||||
_, obj, err := request.Get(daemonHost(), "/networks/"+id)
|
_, obj, err := request.Get("/networks/" + id)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
nr := types.NetworkResource{}
|
nr := types.NetworkResource{}
|
||||||
|
@ -308,7 +308,7 @@ func getNetworkResource(c *check.C, id string) *types.NetworkResource {
|
||||||
}
|
}
|
||||||
|
|
||||||
func createNetwork(c *check.C, config types.NetworkCreateRequest, shouldSucceed bool) string {
|
func createNetwork(c *check.C, config types.NetworkCreateRequest, shouldSucceed bool) string {
|
||||||
resp, body, err := request.Post(daemonHost(), "/networks/create", request.JSONBody(config))
|
resp, body, err := request.Post("/networks/create", request.JSONBody(config))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if !shouldSucceed {
|
if !shouldSucceed {
|
||||||
|
@ -330,7 +330,7 @@ func connectNetwork(c *check.C, nid, cid string) {
|
||||||
Container: cid,
|
Container: cid,
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, _, err := request.Post(daemonHost(), "/networks/"+nid+"/connect", request.JSONBody(config))
|
resp, _, err := request.Post("/networks/"+nid+"/connect", request.JSONBody(config))
|
||||||
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
}
|
}
|
||||||
|
@ -340,13 +340,13 @@ func disconnectNetwork(c *check.C, nid, cid string) {
|
||||||
Container: cid,
|
Container: cid,
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, _, err := request.Post(daemonHost(), "/networks/"+nid+"/disconnect", request.JSONBody(config))
|
resp, _, err := request.Post("/networks/"+nid+"/disconnect", request.JSONBody(config))
|
||||||
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteNetwork(c *check.C, id string, shouldSucceed bool) {
|
func deleteNetwork(c *check.C, id string, shouldSucceed bool) {
|
||||||
resp, _, err := request.Delete(daemonHost(), "/networks/"+id)
|
resp, _, err := request.Delete("/networks/" + id)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if !shouldSucceed {
|
if !shouldSucceed {
|
||||||
|
|
|
@ -26,7 +26,7 @@ func (s *DockerSuite) TestAPIStatsNoStreamGetCpu(c *check.C) {
|
||||||
id := strings.TrimSpace(out)
|
id := strings.TrimSpace(out)
|
||||||
c.Assert(waitRun(id), checker.IsNil)
|
c.Assert(waitRun(id), checker.IsNil)
|
||||||
|
|
||||||
resp, body, err := request.Get(daemonHost(), fmt.Sprintf("/containers/%s/stats?stream=false", id))
|
resp, body, err := request.Get(fmt.Sprintf("/containers/%s/stats?stream=false", id))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
||||||
c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json")
|
c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json")
|
||||||
|
@ -65,7 +65,7 @@ func (s *DockerSuite) TestAPIStatsStoppedContainerInGoroutines(c *check.C) {
|
||||||
id := strings.TrimSpace(out)
|
id := strings.TrimSpace(out)
|
||||||
|
|
||||||
getGoRoutines := func() int {
|
getGoRoutines := func() int {
|
||||||
_, body, err := request.Get(daemonHost(), fmt.Sprintf("/info"))
|
_, body, err := request.Get(fmt.Sprintf("/info"))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
info := types.Info{}
|
info := types.Info{}
|
||||||
err = json.NewDecoder(body).Decode(&info)
|
err = json.NewDecoder(body).Decode(&info)
|
||||||
|
@ -76,7 +76,7 @@ func (s *DockerSuite) TestAPIStatsStoppedContainerInGoroutines(c *check.C) {
|
||||||
|
|
||||||
// When the HTTP connection is closed, the number of goroutines should not increase.
|
// When the HTTP connection is closed, the number of goroutines should not increase.
|
||||||
routines := getGoRoutines()
|
routines := getGoRoutines()
|
||||||
_, body, err := request.Get(daemonHost(), fmt.Sprintf("/containers/%s/stats", id))
|
_, body, err := request.Get(fmt.Sprintf("/containers/%s/stats", id))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
body.Close()
|
body.Close()
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ func (s *DockerSuite) TestAPIStatsNetworkStatsVersioning(c *check.C) {
|
||||||
func getNetworkStats(c *check.C, id string) map[string]types.NetworkStats {
|
func getNetworkStats(c *check.C, id string) map[string]types.NetworkStats {
|
||||||
var st *types.StatsJSON
|
var st *types.StatsJSON
|
||||||
|
|
||||||
_, body, err := request.Get(daemonHost(), fmt.Sprintf("/containers/%s/stats?stream=false", id))
|
_, body, err := request.Get(fmt.Sprintf("/containers/%s/stats?stream=false", id))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
err = json.NewDecoder(body).Decode(&st)
|
err = json.NewDecoder(body).Decode(&st)
|
||||||
|
@ -209,7 +209,7 @@ func getNetworkStats(c *check.C, id string) map[string]types.NetworkStats {
|
||||||
func getVersionedStats(c *check.C, id string, apiVersion string) map[string]interface{} {
|
func getVersionedStats(c *check.C, id string, apiVersion string) map[string]interface{} {
|
||||||
stats := make(map[string]interface{})
|
stats := make(map[string]interface{})
|
||||||
|
|
||||||
_, body, err := request.Get(daemonHost(), fmt.Sprintf("/%s/containers/%s/stats?stream=false", apiVersion, id))
|
_, body, err := request.Get(fmt.Sprintf("/%s/containers/%s/stats?stream=false", apiVersion, id))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
defer body.Close()
|
defer body.Close()
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ func (s *DockerSuite) TestAPIStatsNoStreamConnectedContainers(c *check.C) {
|
||||||
|
|
||||||
ch := make(chan error)
|
ch := make(chan error)
|
||||||
go func() {
|
go func() {
|
||||||
resp, body, err := request.Get(daemonHost(), fmt.Sprintf("/containers/%s/stats?stream=false", id2))
|
resp, body, err := request.Get(fmt.Sprintf("/containers/%s/stats?stream=false", id2))
|
||||||
defer body.Close()
|
defer body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ch <- err
|
ch <- err
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
func (s *DockerSuite) TestAPIStatsContainerGetMemoryLimit(c *check.C) {
|
func (s *DockerSuite) TestAPIStatsContainerGetMemoryLimit(c *check.C) {
|
||||||
testRequires(c, DaemonIsLinux, memoryLimitSupport)
|
testRequires(c, DaemonIsLinux, memoryLimitSupport)
|
||||||
|
|
||||||
resp, body, err := request.Get(daemonHost(), "/info", request.JSON)
|
resp, body, err := request.Get("/info", request.JSON)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
||||||
var info types.Info
|
var info types.Info
|
||||||
|
@ -29,7 +29,7 @@ func (s *DockerSuite) TestAPIStatsContainerGetMemoryLimit(c *check.C) {
|
||||||
dockerCmd(c, "run", "-d", "--name", conName, "busybox", "top")
|
dockerCmd(c, "run", "-d", "--name", conName, "busybox", "top")
|
||||||
c.Assert(waitRun(conName), checker.IsNil)
|
c.Assert(waitRun(conName), checker.IsNil)
|
||||||
|
|
||||||
resp, body, err = request.Get(daemonHost(), fmt.Sprintf("/containers/%s/stats?stream=false", conName))
|
resp, body, err = request.Get(fmt.Sprintf("/containers/%s/stats?stream=false", conName))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
||||||
c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json")
|
c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json")
|
||||||
|
|
|
@ -18,13 +18,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *DockerSuite) TestAPIOptionsRoute(c *check.C) {
|
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(err, checker.IsNil)
|
||||||
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestAPIGetEnabledCORS(c *check.C) {
|
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(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||||
body.Close()
|
body.Close()
|
||||||
|
@ -49,7 +49,7 @@ func (s *DockerSuite) TestAPIClientVersionOldNotSupported(c *check.C) {
|
||||||
v[1] = strconv.Itoa(vMinInt)
|
v[1] = strconv.Itoa(vMinInt)
|
||||||
version := strings.Join(v, ".")
|
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)
|
c.Assert(err, checker.IsNil)
|
||||||
defer body.Close()
|
defer body.Close()
|
||||||
c.Assert(resp.StatusCode, checker.Equals, http.StatusBadRequest)
|
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) {
|
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(err, checker.IsNil)
|
||||||
c.Assert(httpResp.StatusCode, checker.Equals, http.StatusInternalServerError)
|
c.Assert(httpResp.StatusCode, checker.Equals, http.StatusInternalServerError)
|
||||||
c.Assert(httpResp.Header.Get("Content-Type"), checker.Equals, "application/json")
|
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
|
// 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
|
// in v1.23, but changed in 1.24, hence not applicable on Windows. See apiVersionSupportsJSONErrors
|
||||||
testRequires(c, DaemonIsLinux)
|
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(err, checker.IsNil)
|
||||||
c.Assert(httpResp.StatusCode, checker.Equals, http.StatusInternalServerError)
|
c.Assert(httpResp.StatusCode, checker.Equals, http.StatusInternalServerError)
|
||||||
c.Assert(httpResp.Header.Get("Content-Type"), checker.Contains, "text/plain")
|
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) {
|
func (s *DockerSuite) TestAPIErrorNotFoundJSON(c *check.C) {
|
||||||
// 404 is a different code path to normal errors, so test separately
|
// 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(err, checker.IsNil)
|
||||||
c.Assert(httpResp.StatusCode, checker.Equals, http.StatusNotFound)
|
c.Assert(httpResp.StatusCode, checker.Equals, http.StatusNotFound)
|
||||||
c.Assert(httpResp.Header.Get("Content-Type"), checker.Equals, "application/json")
|
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) {
|
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(err, checker.IsNil)
|
||||||
c.Assert(httpResp.StatusCode, checker.Equals, http.StatusNotFound)
|
c.Assert(httpResp.StatusCode, checker.Equals, http.StatusNotFound)
|
||||||
c.Assert(httpResp.Header.Get("Content-Type"), checker.Contains, "text/plain")
|
c.Assert(httpResp.Header.Get("Content-Type"), checker.Contains, "text/plain")
|
||||||
|
|
|
@ -220,7 +220,7 @@ func (s *DockerSuite) TestUpdateStats(c *check.C) {
|
||||||
c.Assert(waitRun(name), checker.IsNil)
|
c.Assert(waitRun(name), checker.IsNil)
|
||||||
|
|
||||||
getMemLimit := func(id string) uint64 {
|
getMemLimit := func(id string) uint64 {
|
||||||
resp, body, err := request.Get(daemonHost(), fmt.Sprintf("/containers/%s/stats?stream=false", id))
|
resp, body, err := request.Get(fmt.Sprintf("/containers/%s/stats?stream=false", id))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json")
|
c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json")
|
||||||
|
|
||||||
|
|
|
@ -150,7 +150,7 @@ func (s *DockerSuite) TestDeprecatedStartWithTooLowMemoryLimit(c *check.C) {
|
||||||
"Memory": 524287
|
"Memory": 524287
|
||||||
}`
|
}`
|
||||||
|
|
||||||
res, body, err := request.Post(daemonHost(), formatV123StartAPIURL("/containers/"+containerID+"/start"), request.RawString(config), request.JSON)
|
res, body, err := request.Post(formatV123StartAPIURL("/containers/"+containerID+"/start"), request.RawString(config), request.JSON)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
b, err2 := testutil.ReadBody(body)
|
b, err2 := testutil.ReadBody(body)
|
||||||
c.Assert(err2, checker.IsNil)
|
c.Assert(err2, checker.IsNil)
|
||||||
|
@ -169,7 +169,7 @@ func (s *DockerSuite) TestDeprecatedPostContainersStartWithoutLinksInHostConfig(
|
||||||
hc := inspectFieldJSON(c, name, "HostConfig")
|
hc := inspectFieldJSON(c, name, "HostConfig")
|
||||||
config := `{"HostConfig":` + hc + `}`
|
config := `{"HostConfig":` + hc + `}`
|
||||||
|
|
||||||
res, b, err := request.Post(daemonHost(), formatV123StartAPIURL("/containers/"+name+"/start"), request.RawString(config), request.JSON)
|
res, b, err := request.Post(formatV123StartAPIURL("/containers/"+name+"/start"), request.RawString(config), request.JSON)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent)
|
||||||
b.Close()
|
b.Close()
|
||||||
|
@ -187,7 +187,7 @@ func (s *DockerSuite) TestDeprecatedPostContainersStartWithLinksInHostConfig(c *
|
||||||
hc := inspectFieldJSON(c, name, "HostConfig")
|
hc := inspectFieldJSON(c, name, "HostConfig")
|
||||||
config := `{"HostConfig":` + hc + `}`
|
config := `{"HostConfig":` + hc + `}`
|
||||||
|
|
||||||
res, b, err := request.Post(daemonHost(), formatV123StartAPIURL("/containers/"+name+"/start"), request.RawString(config), request.JSON)
|
res, b, err := request.Post(formatV123StartAPIURL("/containers/"+name+"/start"), request.RawString(config), request.JSON)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent)
|
||||||
b.Close()
|
b.Close()
|
||||||
|
@ -205,7 +205,7 @@ func (s *DockerSuite) TestDeprecatedPostContainersStartWithLinksInHostConfigIdLi
|
||||||
hc := inspectFieldJSON(c, name, "HostConfig")
|
hc := inspectFieldJSON(c, name, "HostConfig")
|
||||||
config := `{"HostConfig":` + hc + `}`
|
config := `{"HostConfig":` + hc + `}`
|
||||||
|
|
||||||
res, b, err := request.Post(daemonHost(), formatV123StartAPIURL("/containers/"+name+"/start"), request.RawString(config), request.JSON)
|
res, b, err := request.Post(formatV123StartAPIURL("/containers/"+name+"/start"), request.RawString(config), request.JSON)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent)
|
||||||
b.Close()
|
b.Close()
|
||||||
|
@ -219,7 +219,7 @@ func (s *DockerSuite) TestDeprecatedStartWithNilDNS(c *check.C) {
|
||||||
|
|
||||||
config := `{"HostConfig": {"Dns": null}}`
|
config := `{"HostConfig": {"Dns": null}}`
|
||||||
|
|
||||||
res, b, err := request.Post(daemonHost(), formatV123StartAPIURL("/containers/"+containerID+"/start"), request.RawString(config), request.JSON)
|
res, b, err := request.Post(formatV123StartAPIURL("/containers/"+containerID+"/start"), request.RawString(config), request.JSON)
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent)
|
||||||
b.Close()
|
b.Close()
|
||||||
|
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/integration-cli/checker"
|
"github.com/docker/docker/integration-cli/checker"
|
||||||
"github.com/docker/docker/integration-cli/daemon"
|
"github.com/docker/docker/integration-cli/daemon"
|
||||||
"github.com/docker/docker/integration-cli/environment"
|
|
||||||
"github.com/docker/docker/integration-cli/registry"
|
"github.com/docker/docker/integration-cli/registry"
|
||||||
"github.com/docker/docker/integration-cli/request"
|
"github.com/docker/docker/integration-cli/request"
|
||||||
"github.com/docker/docker/pkg/stringutils"
|
"github.com/docker/docker/pkg/stringutils"
|
||||||
|
@ -32,7 +31,7 @@ import (
|
||||||
|
|
||||||
// Deprecated
|
// Deprecated
|
||||||
func daemonHost() string {
|
func daemonHost() string {
|
||||||
return environment.DaemonHost()
|
return request.DaemonHost()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(vdemeester) move this away are remove ignoreNoSuchContainer bool
|
// FIXME(vdemeester) move this away are remove ignoreNoSuchContainer bool
|
||||||
|
|
|
@ -4,13 +4,11 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
volumetypes "github.com/docker/docker/api/types/volume"
|
volumetypes "github.com/docker/docker/api/types/volume"
|
||||||
"github.com/docker/docker/integration-cli/request"
|
"github.com/docker/docker/integration-cli/request"
|
||||||
"github.com/docker/docker/opts"
|
|
||||||
icmd "github.com/docker/docker/pkg/testutil/cmd"
|
icmd "github.com/docker/docker/pkg/testutil/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -111,7 +109,7 @@ func deleteAllVolumes(t testingT, dockerBinary string) {
|
||||||
}
|
}
|
||||||
var errs []string
|
var errs []string
|
||||||
for _, v := range volumes {
|
for _, v := range volumes {
|
||||||
status, b, err := request.SockRequest("DELETE", "/volumes/"+v.Name, nil, DaemonHost())
|
status, b, err := request.SockRequest("DELETE", "/volumes/"+v.Name, nil, request.DaemonHost())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = append(errs, err.Error())
|
errs = append(errs, err.Error())
|
||||||
continue
|
continue
|
||||||
|
@ -127,7 +125,7 @@ func deleteAllVolumes(t testingT, dockerBinary string) {
|
||||||
|
|
||||||
func getAllVolumes() ([]*types.Volume, error) {
|
func getAllVolumes() ([]*types.Volume, error) {
|
||||||
var volumes volumetypes.VolumesListOKBody
|
var volumes volumetypes.VolumesListOKBody
|
||||||
_, b, err := request.SockRequest("GET", "/volumes", nil, DaemonHost())
|
_, b, err := request.SockRequest("GET", "/volumes", nil, request.DaemonHost())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -151,7 +149,7 @@ func deleteAllNetworks(t testingT, dockerBinary string, daemonPlatform string) {
|
||||||
// nat is a pre-defined network on Windows and cannot be removed
|
// nat is a pre-defined network on Windows and cannot be removed
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
status, b, err := request.SockRequest("DELETE", "/networks/"+n.Name, nil, DaemonHost())
|
status, b, err := request.SockRequest("DELETE", "/networks/"+n.Name, nil, request.DaemonHost())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = append(errs, err.Error())
|
errs = append(errs, err.Error())
|
||||||
continue
|
continue
|
||||||
|
@ -167,7 +165,7 @@ func deleteAllNetworks(t testingT, dockerBinary string, daemonPlatform string) {
|
||||||
|
|
||||||
func getAllNetworks() ([]types.NetworkResource, error) {
|
func getAllNetworks() ([]types.NetworkResource, error) {
|
||||||
var networks []types.NetworkResource
|
var networks []types.NetworkResource
|
||||||
_, b, err := request.SockRequest("GET", "/networks", nil, DaemonHost())
|
_, b, err := request.SockRequest("GET", "/networks", nil, request.DaemonHost())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -185,7 +183,7 @@ func deleteAllPlugins(t testingT, dockerBinary string) {
|
||||||
var errs []string
|
var errs []string
|
||||||
for _, p := range plugins {
|
for _, p := range plugins {
|
||||||
pluginName := p.Name
|
pluginName := p.Name
|
||||||
status, b, err := request.SockRequest("DELETE", "/plugins/"+pluginName+"?force=1", nil, DaemonHost())
|
status, b, err := request.SockRequest("DELETE", "/plugins/"+pluginName+"?force=1", nil, request.DaemonHost())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = append(errs, err.Error())
|
errs = append(errs, err.Error())
|
||||||
continue
|
continue
|
||||||
|
@ -201,7 +199,7 @@ func deleteAllPlugins(t testingT, dockerBinary string) {
|
||||||
|
|
||||||
func getAllPlugins() (types.PluginsListResponse, error) {
|
func getAllPlugins() (types.PluginsListResponse, error) {
|
||||||
var plugins types.PluginsListResponse
|
var plugins types.PluginsListResponse
|
||||||
_, b, err := request.SockRequest("GET", "/plugins", nil, DaemonHost())
|
_, b, err := request.SockRequest("GET", "/plugins", nil, request.DaemonHost())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -210,12 +208,3 @@ func getAllPlugins() (types.PluginsListResponse, error) {
|
||||||
}
|
}
|
||||||
return plugins, nil
|
return plugins, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DaemonHost return the daemon host string for this test execution
|
|
||||||
func DaemonHost() string {
|
|
||||||
daemonURLStr := "unix://" + opts.DefaultUnixSocket
|
|
||||||
if daemonHostVar := os.Getenv("DOCKER_HOST"); daemonHostVar != "" {
|
|
||||||
daemonURLStr = daemonHostVar
|
|
||||||
}
|
|
||||||
return daemonURLStr
|
|
||||||
}
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
dclient "github.com/docker/docker/client"
|
dclient "github.com/docker/docker/client"
|
||||||
|
"github.com/docker/docker/opts"
|
||||||
"github.com/docker/docker/pkg/ioutils"
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
"github.com/docker/docker/pkg/testutil"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/go-connections/sockets"
|
"github.com/docker/go-connections/sockets"
|
||||||
|
@ -74,22 +75,27 @@ func JSONBody(data interface{}) func(*http.Request) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Post creates and execute a POST request on the specified host and endpoint, with the specified request modifiers
|
// Post creates and execute a POST request on the specified host and endpoint, with the specified request modifiers
|
||||||
func Post(host, endpoint string, modifiers ...func(*http.Request) error) (*http.Response, io.ReadCloser, error) {
|
func Post(endpoint string, modifiers ...func(*http.Request) error) (*http.Response, io.ReadCloser, error) {
|
||||||
return Do(host, endpoint, append(modifiers, Method(http.MethodPost))...)
|
return Do(endpoint, append(modifiers, Method(http.MethodPost))...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete creates and execute a DELETE request on the specified host and endpoint, with the specified request modifiers
|
// Delete creates and execute a DELETE request on the specified host and endpoint, with the specified request modifiers
|
||||||
func Delete(host, endpoint string, modifiers ...func(*http.Request) error) (*http.Response, io.ReadCloser, error) {
|
func Delete(endpoint string, modifiers ...func(*http.Request) error) (*http.Response, io.ReadCloser, error) {
|
||||||
return Do(host, endpoint, append(modifiers, Method(http.MethodDelete))...)
|
return Do(endpoint, append(modifiers, Method(http.MethodDelete))...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get creates and execute a GET request on the specified host and endpoint, with the specified request modifiers
|
// Get creates and execute a GET request on the specified host and endpoint, with the specified request modifiers
|
||||||
func Get(host, endpoint string, modifiers ...func(*http.Request) error) (*http.Response, io.ReadCloser, error) {
|
func Get(endpoint string, modifiers ...func(*http.Request) error) (*http.Response, io.ReadCloser, error) {
|
||||||
return Do(host, endpoint, modifiers...)
|
return Do(endpoint, modifiers...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do creates and execute a request on the specified host and endpoint, with the specified request modifiers
|
// Do creates and execute a request on the specified endpoint, with the specified request modifiers
|
||||||
func Do(host, endpoint string, modifiers ...func(*http.Request) error) (*http.Response, io.ReadCloser, error) {
|
func Do(endpoint string, modifiers ...func(*http.Request) error) (*http.Response, io.ReadCloser, error) {
|
||||||
|
return DoOnHost(DaemonHost(), endpoint, modifiers...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoOnHost creates and execute a request on the specified host and endpoint, with the specified request modifiers
|
||||||
|
func DoOnHost(host, endpoint string, modifiers ...func(*http.Request) error) (*http.Response, io.ReadCloser, error) {
|
||||||
req, err := New(host, endpoint, modifiers...)
|
req, err := New(host, endpoint, modifiers...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
@ -283,3 +289,12 @@ func getTLSConfig() (*tls.Config, error) {
|
||||||
|
|
||||||
return tlsConfig, nil
|
return tlsConfig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DaemonHost return the daemon host string for this test execution
|
||||||
|
func DaemonHost() string {
|
||||||
|
daemonURLStr := "unix://" + opts.DefaultUnixSocket
|
||||||
|
if daemonHostVar := os.Getenv("DOCKER_HOST"); daemonHostVar != "" {
|
||||||
|
daemonURLStr = daemonHostVar
|
||||||
|
}
|
||||||
|
return daemonURLStr
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue