[test-integration] Add a new request package in integration-cli
| ... | ... |
@@ -2,15 +2,11 @@ package daemon |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"bytes" |
| 5 |
- "crypto/tls" |
|
| 6 | 5 |
"encoding/json" |
| 7 | 6 |
"fmt" |
| 8 | 7 |
"io" |
| 9 | 8 |
"io/ioutil" |
| 10 |
- "net" |
|
| 11 | 9 |
"net/http" |
| 12 |
- "net/http/httputil" |
|
| 13 |
- "net/url" |
|
| 14 | 10 |
"os" |
| 15 | 11 |
"os/exec" |
| 16 | 12 |
"path/filepath" |
| ... | ... |
@@ -20,6 +16,7 @@ import ( |
| 20 | 20 |
|
| 21 | 21 |
"github.com/docker/docker/api/types/events" |
| 22 | 22 |
"github.com/docker/docker/integration-cli/checker" |
| 23 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 23 | 24 |
"github.com/docker/docker/opts" |
| 24 | 25 |
"github.com/docker/docker/pkg/ioutils" |
| 25 | 26 |
"github.com/docker/docker/pkg/stringid" |
| ... | ... |
@@ -624,7 +621,7 @@ func (d *Daemon) SockRequest(method, endpoint string, data interface{}) (int, []
|
| 624 | 624 |
// SockRequestRaw executes a socket request on a daemon and returns an http |
| 625 | 625 |
// response and a reader for the output data. |
| 626 | 626 |
func (d *Daemon) SockRequestRaw(method, endpoint string, data io.Reader, ct string) (*http.Response, io.ReadCloser, error) {
|
| 627 |
- return SockRequestRawToDaemon(method, endpoint, data, ct, d.Sock()) |
|
| 627 |
+ return request.SockRequestRaw(method, endpoint, data, ct, d.Sock()) |
|
| 628 | 628 |
} |
| 629 | 629 |
|
| 630 | 630 |
// LogFileName returns the path the daemon's log file |
| ... | ... |
@@ -714,7 +711,7 @@ func (d *Daemon) ReloadConfig() error {
|
| 714 | 714 |
errCh := make(chan error) |
| 715 | 715 |
started := make(chan struct{})
|
| 716 | 716 |
go func() {
|
| 717 |
- _, body, err := SockRequestRawToDaemon("GET", "/events", nil, "", d.Sock())
|
|
| 717 |
+ _, body, err := request.SockRequestRaw("GET", "/events", nil, "", d.Sock())
|
|
| 718 | 718 |
close(started) |
| 719 | 719 |
if err != nil {
|
| 720 | 720 |
errCh <- err |
| ... | ... |
@@ -791,96 +788,6 @@ func WaitInspectWithArgs(dockerBinary, name, expr, expected string, timeout time |
| 791 | 791 |
return nil |
| 792 | 792 |
} |
| 793 | 793 |
|
| 794 |
-// SockRequestRawToDaemon creates an http request against the specified daemon socket |
|
| 795 |
-// FIXME(vdemeester) attach this to daemon ? |
|
| 796 |
-func SockRequestRawToDaemon(method, endpoint string, data io.Reader, ct, daemon string) (*http.Response, io.ReadCloser, error) {
|
|
| 797 |
- req, client, err := newRequestClient(method, endpoint, data, ct, daemon) |
|
| 798 |
- if err != nil {
|
|
| 799 |
- return nil, nil, err |
|
| 800 |
- } |
|
| 801 |
- |
|
| 802 |
- resp, err := client.Do(req) |
|
| 803 |
- if err != nil {
|
|
| 804 |
- client.Close() |
|
| 805 |
- return nil, nil, err |
|
| 806 |
- } |
|
| 807 |
- body := ioutils.NewReadCloserWrapper(resp.Body, func() error {
|
|
| 808 |
- defer resp.Body.Close() |
|
| 809 |
- return client.Close() |
|
| 810 |
- }) |
|
| 811 |
- |
|
| 812 |
- return resp, body, nil |
|
| 813 |
-} |
|
| 814 |
- |
|
| 815 |
-func getTLSConfig() (*tls.Config, error) {
|
|
| 816 |
- dockerCertPath := os.Getenv("DOCKER_CERT_PATH")
|
|
| 817 |
- |
|
| 818 |
- if dockerCertPath == "" {
|
|
| 819 |
- return nil, errors.New("DOCKER_TLS_VERIFY specified, but no DOCKER_CERT_PATH environment variable")
|
|
| 820 |
- } |
|
| 821 |
- |
|
| 822 |
- option := &tlsconfig.Options{
|
|
| 823 |
- CAFile: filepath.Join(dockerCertPath, "ca.pem"), |
|
| 824 |
- CertFile: filepath.Join(dockerCertPath, "cert.pem"), |
|
| 825 |
- KeyFile: filepath.Join(dockerCertPath, "key.pem"), |
|
| 826 |
- } |
|
| 827 |
- tlsConfig, err := tlsconfig.Client(*option) |
|
| 828 |
- if err != nil {
|
|
| 829 |
- return nil, err |
|
| 830 |
- } |
|
| 831 |
- |
|
| 832 |
- return tlsConfig, nil |
|
| 833 |
-} |
|
| 834 |
- |
|
| 835 |
-// SockConn opens a connection on the specified socket |
|
| 836 |
-func SockConn(timeout time.Duration, daemon string) (net.Conn, error) {
|
|
| 837 |
- daemonURL, err := url.Parse(daemon) |
|
| 838 |
- if err != nil {
|
|
| 839 |
- return nil, errors.Wrapf(err, "could not parse url %q", daemon) |
|
| 840 |
- } |
|
| 841 |
- |
|
| 842 |
- var c net.Conn |
|
| 843 |
- switch daemonURL.Scheme {
|
|
| 844 |
- case "npipe": |
|
| 845 |
- return npipeDial(daemonURL.Path, timeout) |
|
| 846 |
- case "unix": |
|
| 847 |
- return net.DialTimeout(daemonURL.Scheme, daemonURL.Path, timeout) |
|
| 848 |
- case "tcp": |
|
| 849 |
- if os.Getenv("DOCKER_TLS_VERIFY") != "" {
|
|
| 850 |
- // Setup the socket TLS configuration. |
|
| 851 |
- tlsConfig, err := getTLSConfig() |
|
| 852 |
- if err != nil {
|
|
| 853 |
- return nil, err |
|
| 854 |
- } |
|
| 855 |
- dialer := &net.Dialer{Timeout: timeout}
|
|
| 856 |
- return tls.DialWithDialer(dialer, daemonURL.Scheme, daemonURL.Host, tlsConfig) |
|
| 857 |
- } |
|
| 858 |
- return net.DialTimeout(daemonURL.Scheme, daemonURL.Host, timeout) |
|
| 859 |
- default: |
|
| 860 |
- return c, errors.Errorf("unknown scheme %v (%s)", daemonURL.Scheme, daemon)
|
|
| 861 |
- } |
|
| 862 |
-} |
|
| 863 |
- |
|
| 864 |
-func newRequestClient(method, endpoint string, data io.Reader, ct, daemon string) (*http.Request, *httputil.ClientConn, error) {
|
|
| 865 |
- c, err := SockConn(time.Duration(10*time.Second), daemon) |
|
| 866 |
- if err != nil {
|
|
| 867 |
- return nil, nil, errors.Errorf("could not dial docker daemon: %v", err)
|
|
| 868 |
- } |
|
| 869 |
- |
|
| 870 |
- client := httputil.NewClientConn(c, nil) |
|
| 871 |
- |
|
| 872 |
- req, err := http.NewRequest(method, endpoint, data) |
|
| 873 |
- if err != nil {
|
|
| 874 |
- client.Close() |
|
| 875 |
- return nil, nil, errors.Errorf("could not create new request: %v", err)
|
|
| 876 |
- } |
|
| 877 |
- |
|
| 878 |
- if ct != "" {
|
|
| 879 |
- req.Header.Set("Content-Type", ct)
|
|
| 880 |
- } |
|
| 881 |
- return req, client, nil |
|
| 882 |
-} |
|
| 883 |
- |
|
| 884 | 794 |
// BuildImageCmdWithHost create a build command with the specified arguments. |
| 885 | 795 |
// FIXME(vdemeester) move this away |
| 886 | 796 |
func BuildImageCmdWithHost(dockerBinary, name, dockerfile, host string, useCache bool, buildFlags ...string) *exec.Cmd {
|
| ... | ... |
@@ -13,6 +13,7 @@ import ( |
| 13 | 13 |
"github.com/docker/docker/api/types" |
| 14 | 14 |
"github.com/docker/docker/client" |
| 15 | 15 |
"github.com/docker/docker/integration-cli/checker" |
| 16 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 16 | 17 |
"github.com/docker/docker/pkg/stdcopy" |
| 17 | 18 |
"github.com/docker/docker/pkg/testutil" |
| 18 | 19 |
"github.com/go-check/check" |
| ... | ... |
@@ -23,7 +24,7 @@ func (s *DockerSuite) TestGetContainersAttachWebsocket(c *check.C) {
|
| 23 | 23 |
testRequires(c, DaemonIsLinux) |
| 24 | 24 |
out, _ := dockerCmd(c, "run", "-dit", "busybox", "cat") |
| 25 | 25 |
|
| 26 |
- rwc, err := sockConn(time.Duration(10*time.Second), "") |
|
| 26 |
+ rwc, err := request.SockConn(time.Duration(10*time.Second), daemonHost()) |
|
| 27 | 27 |
c.Assert(err, checker.IsNil) |
| 28 | 28 |
|
| 29 | 29 |
cleanedContainerID := strings.TrimSpace(out) |
| ... | ... |
@@ -73,22 +74,20 @@ func (s *DockerSuite) TestGetContainersAttachWebsocket(c *check.C) {
|
| 73 | 73 |
|
| 74 | 74 |
// regression gh14320 |
| 75 | 75 |
func (s *DockerSuite) TestPostContainersAttachContainerNotFound(c *check.C) {
|
| 76 |
- req, client, err := newRequestClient("POST", "/containers/doesnotexist/attach", nil, "", "")
|
|
| 76 |
+ client, err := request.NewClient(daemonHost()) |
|
| 77 | 77 |
c.Assert(err, checker.IsNil) |
| 78 |
- |
|
| 78 |
+ req, err := request.New(daemonHost(), "/containers/doesnotexist/attach", request.Method(http.MethodPost)) |
|
| 79 | 79 |
resp, err := client.Do(req) |
| 80 | 80 |
// connection will shutdown, err should be "persistent connection closed" |
| 81 |
- c.Assert(err, checker.NotNil) // Server shutdown connection |
|
| 82 |
- |
|
| 83 |
- body, err := testutil.ReadBody(resp.Body) |
|
| 84 |
- c.Assert(err, checker.IsNil) |
|
| 85 | 81 |
c.Assert(resp.StatusCode, checker.Equals, http.StatusNotFound) |
| 82 |
+ content, err := testutil.ReadBody(resp.Body) |
|
| 83 |
+ c.Assert(err, checker.IsNil) |
|
| 86 | 84 |
expected := "No such container: doesnotexist\r\n" |
| 87 |
- c.Assert(string(body), checker.Equals, expected) |
|
| 85 |
+ c.Assert(string(content), checker.Equals, expected) |
|
| 88 | 86 |
} |
| 89 | 87 |
|
| 90 | 88 |
func (s *DockerSuite) TestGetContainersWsAttachContainerNotFound(c *check.C) {
|
| 91 |
- status, body, err := sockRequest("GET", "/containers/doesnotexist/attach/ws", nil)
|
|
| 89 |
+ status, body, err := request.SockRequest("GET", "/containers/doesnotexist/attach/ws", nil, daemonHost())
|
|
| 92 | 90 |
c.Assert(status, checker.Equals, http.StatusNotFound) |
| 93 | 91 |
c.Assert(err, checker.IsNil) |
| 94 | 92 |
expected := "No such container: doesnotexist" |
| ... | ... |
@@ -140,12 +139,12 @@ func (s *DockerSuite) TestPostContainersAttach(c *check.C) {
|
| 140 | 140 |
cid, _ := dockerCmd(c, "run", "-di", "busybox", "cat") |
| 141 | 141 |
cid = strings.TrimSpace(cid) |
| 142 | 142 |
// Attach to the container's stdout stream. |
| 143 |
- conn, br, err := sockRequestHijack("POST", "/containers/"+cid+"/attach?stream=1&stdin=1&stdout=1", nil, "text/plain")
|
|
| 143 |
+ conn, br, err := request.SockRequestHijack("POST", "/containers/"+cid+"/attach?stream=1&stdin=1&stdout=1", nil, "text/plain", daemonHost())
|
|
| 144 | 144 |
c.Assert(err, checker.IsNil) |
| 145 | 145 |
// Check if the data from stdout can be received. |
| 146 | 146 |
expectSuccess(conn, br, "stdout", false) |
| 147 | 147 |
// Attach to the container's stderr stream. |
| 148 |
- conn, br, err = sockRequestHijack("POST", "/containers/"+cid+"/attach?stream=1&stdin=1&stderr=1", nil, "text/plain")
|
|
| 148 |
+ conn, br, err = request.SockRequestHijack("POST", "/containers/"+cid+"/attach?stream=1&stdin=1&stderr=1", nil, "text/plain", daemonHost())
|
|
| 149 | 149 |
c.Assert(err, checker.IsNil) |
| 150 | 150 |
// Since the container only emits stdout, attaching to stderr should return nothing. |
| 151 | 151 |
expectTimeout(conn, br, "stdout") |
| ... | ... |
@@ -153,10 +152,10 @@ func (s *DockerSuite) TestPostContainersAttach(c *check.C) {
|
| 153 | 153 |
// Test the similar functions of the stderr stream. |
| 154 | 154 |
cid, _ = dockerCmd(c, "run", "-di", "busybox", "/bin/sh", "-c", "cat >&2") |
| 155 | 155 |
cid = strings.TrimSpace(cid) |
| 156 |
- conn, br, err = sockRequestHijack("POST", "/containers/"+cid+"/attach?stream=1&stdin=1&stderr=1", nil, "text/plain")
|
|
| 156 |
+ conn, br, err = request.SockRequestHijack("POST", "/containers/"+cid+"/attach?stream=1&stdin=1&stderr=1", nil, "text/plain", daemonHost())
|
|
| 157 | 157 |
c.Assert(err, checker.IsNil) |
| 158 | 158 |
expectSuccess(conn, br, "stderr", false) |
| 159 |
- conn, br, err = sockRequestHijack("POST", "/containers/"+cid+"/attach?stream=1&stdin=1&stdout=1", nil, "text/plain")
|
|
| 159 |
+ conn, br, err = request.SockRequestHijack("POST", "/containers/"+cid+"/attach?stream=1&stdin=1&stdout=1", nil, "text/plain", daemonHost())
|
|
| 160 | 160 |
c.Assert(err, checker.IsNil) |
| 161 | 161 |
expectTimeout(conn, br, "stderr") |
| 162 | 162 |
|
| ... | ... |
@@ -164,12 +163,12 @@ func (s *DockerSuite) TestPostContainersAttach(c *check.C) {
|
| 164 | 164 |
cid, _ = dockerCmd(c, "run", "-dit", "busybox", "/bin/sh", "-c", "cat >&2") |
| 165 | 165 |
cid = strings.TrimSpace(cid) |
| 166 | 166 |
// Attach to stdout only. |
| 167 |
- conn, br, err = sockRequestHijack("POST", "/containers/"+cid+"/attach?stream=1&stdin=1&stdout=1", nil, "text/plain")
|
|
| 167 |
+ conn, br, err = request.SockRequestHijack("POST", "/containers/"+cid+"/attach?stream=1&stdin=1&stdout=1", nil, "text/plain", daemonHost())
|
|
| 168 | 168 |
c.Assert(err, checker.IsNil) |
| 169 | 169 |
expectSuccess(conn, br, "stdout", true) |
| 170 | 170 |
|
| 171 | 171 |
// Attach without stdout stream. |
| 172 |
- conn, br, err = sockRequestHijack("POST", "/containers/"+cid+"/attach?stream=1&stdin=1&stderr=1", nil, "text/plain")
|
|
| 172 |
+ conn, br, err = request.SockRequestHijack("POST", "/containers/"+cid+"/attach?stream=1&stdin=1&stderr=1", nil, "text/plain", daemonHost())
|
|
| 173 | 173 |
c.Assert(err, checker.IsNil) |
| 174 | 174 |
// Nothing should be received because both the stdout and stderr of the container will be |
| 175 | 175 |
// sent to the client as stdout when tty is enabled. |
| ... | ... |
@@ -5,6 +5,7 @@ import ( |
| 5 | 5 |
|
| 6 | 6 |
"github.com/docker/docker/api/types" |
| 7 | 7 |
"github.com/docker/docker/integration-cli/checker" |
| 8 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 8 | 9 |
"github.com/go-check/check" |
| 9 | 10 |
) |
| 10 | 11 |
|
| ... | ... |
@@ -17,7 +18,7 @@ func (s *DockerSuite) TestAuthAPI(c *check.C) {
|
| 17 | 17 |
} |
| 18 | 18 |
|
| 19 | 19 |
expected := "Get https://registry-1.docker.io/v2/: unauthorized: incorrect username or password" |
| 20 |
- status, body, err := sockRequest("POST", "/auth", config)
|
|
| 20 |
+ status, body, err := request.SockRequest("POST", "/auth", config, daemonHost())
|
|
| 21 | 21 |
c.Assert(err, check.IsNil) |
| 22 | 22 |
c.Assert(status, check.Equals, http.StatusUnauthorized) |
| 23 | 23 |
msg := getErrorMessage(c, body) |
| ... | ... |
@@ -8,6 +8,7 @@ import ( |
| 8 | 8 |
"strings" |
| 9 | 9 |
|
| 10 | 10 |
"github.com/docker/docker/integration-cli/checker" |
| 11 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 11 | 12 |
"github.com/docker/docker/pkg/testutil" |
| 12 | 13 |
"github.com/go-check/check" |
| 13 | 14 |
) |
| ... | ... |
@@ -31,7 +32,7 @@ RUN find /tmp/` |
| 31 | 31 |
c.Assert(err, checker.IsNil) |
| 32 | 32 |
defer server.Close() |
| 33 | 33 |
|
| 34 |
- res, body, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+server.URL()+"/testD", nil, "application/json")
|
|
| 34 |
+ res, body, err := request.SockRequestRaw("POST", "/build?dockerfile=baz&remote="+server.URL()+"/testD", nil, "application/json", daemonHost())
|
|
| 35 | 35 |
c.Assert(err, checker.IsNil) |
| 36 | 36 |
c.Assert(res.StatusCode, checker.Equals, http.StatusOK) |
| 37 | 37 |
|
| ... | ... |
@@ -72,7 +73,7 @@ func (s *DockerSuite) TestBuildAPIRemoteTarballContext(c *check.C) {
|
| 72 | 72 |
|
| 73 | 73 |
defer server.Close() |
| 74 | 74 |
|
| 75 |
- res, b, err := sockRequestRaw("POST", "/build?remote="+server.URL()+"/testT.tar", nil, "application/tar")
|
|
| 75 |
+ res, b, err := request.SockRequestRaw("POST", "/build?remote="+server.URL()+"/testT.tar", nil, "application/tar", daemonHost())
|
|
| 76 | 76 |
c.Assert(err, checker.IsNil) |
| 77 | 77 |
c.Assert(res.StatusCode, checker.Equals, http.StatusOK) |
| 78 | 78 |
b.Close() |
| ... | ... |
@@ -121,7 +122,7 @@ RUN echo 'right' |
| 121 | 121 |
|
| 122 | 122 |
defer server.Close() |
| 123 | 123 |
url := "/build?dockerfile=custom&remote=" + server.URL() + "/testT.tar" |
| 124 |
- res, body, err := sockRequestRaw("POST", url, nil, "application/tar")
|
|
| 124 |
+ res, body, err := request.SockRequestRaw("POST", url, nil, "application/tar", daemonHost())
|
|
| 125 | 125 |
c.Assert(err, checker.IsNil) |
| 126 | 126 |
c.Assert(res.StatusCode, checker.Equals, http.StatusOK) |
| 127 | 127 |
|
| ... | ... |
@@ -141,7 +142,7 @@ RUN echo from dockerfile`, |
| 141 | 141 |
c.Assert(err, checker.IsNil) |
| 142 | 142 |
defer git.Close() |
| 143 | 143 |
|
| 144 |
- res, body, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
|
|
| 144 |
+ res, body, err := request.SockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json", daemonHost())
|
|
| 145 | 145 |
c.Assert(err, checker.IsNil) |
| 146 | 146 |
c.Assert(res.StatusCode, checker.Equals, http.StatusOK) |
| 147 | 147 |
|
| ... | ... |
@@ -163,7 +164,7 @@ RUN echo from Dockerfile`, |
| 163 | 163 |
defer git.Close() |
| 164 | 164 |
|
| 165 | 165 |
// Make sure it tries to 'dockerfile' query param value |
| 166 |
- res, body, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+git.RepoURL, nil, "application/json")
|
|
| 166 |
+ res, body, err := request.SockRequestRaw("POST", "/build?dockerfile=baz&remote="+git.RepoURL, nil, "application/json", daemonHost())
|
|
| 167 | 167 |
c.Assert(err, checker.IsNil) |
| 168 | 168 |
c.Assert(res.StatusCode, checker.Equals, http.StatusOK) |
| 169 | 169 |
|
| ... | ... |
@@ -186,7 +187,7 @@ RUN echo from dockerfile`, |
| 186 | 186 |
defer git.Close() |
| 187 | 187 |
|
| 188 | 188 |
// Make sure it tries to 'dockerfile' query param value |
| 189 |
- res, body, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
|
|
| 189 |
+ res, body, err := request.SockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json", daemonHost())
|
|
| 190 | 190 |
c.Assert(err, checker.IsNil) |
| 191 | 191 |
c.Assert(res.StatusCode, checker.Equals, http.StatusOK) |
| 192 | 192 |
|
| ... | ... |
@@ -233,7 +234,7 @@ func (s *DockerSuite) TestBuildAPIUnnormalizedTarPaths(c *check.C) {
|
| 233 | 233 |
// failed to close tar archive |
| 234 | 234 |
c.Assert(tw.Close(), checker.IsNil) |
| 235 | 235 |
|
| 236 |
- res, body, err := sockRequestRaw("POST", "/build", buffer, "application/x-tar")
|
|
| 236 |
+ res, body, err := request.SockRequestRaw("POST", "/build", buffer, "application/x-tar", daemonHost())
|
|
| 237 | 237 |
c.Assert(err, checker.IsNil) |
| 238 | 238 |
c.Assert(res.StatusCode, checker.Equals, http.StatusOK) |
| 239 | 239 |
|
| ... | ... |
@@ -8,7 +8,6 @@ import ( |
| 8 | 8 |
"io" |
| 9 | 9 |
"io/ioutil" |
| 10 | 10 |
"net/http" |
| 11 |
- "net/http/httputil" |
|
| 12 | 11 |
"net/url" |
| 13 | 12 |
"os" |
| 14 | 13 |
"path/filepath" |
| ... | ... |
@@ -22,6 +21,7 @@ import ( |
| 22 | 22 |
mounttypes "github.com/docker/docker/api/types/mount" |
| 23 | 23 |
networktypes "github.com/docker/docker/api/types/network" |
| 24 | 24 |
"github.com/docker/docker/integration-cli/checker" |
| 25 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 25 | 26 |
"github.com/docker/docker/pkg/ioutils" |
| 26 | 27 |
"github.com/docker/docker/pkg/mount" |
| 27 | 28 |
"github.com/docker/docker/pkg/stringid" |
| ... | ... |
@@ -37,7 +37,7 @@ func (s *DockerSuite) TestContainerAPIGetAll(c *check.C) {
|
| 37 | 37 |
name := "getall" |
| 38 | 38 |
dockerCmd(c, "run", "--name", name, "busybox", "true") |
| 39 | 39 |
|
| 40 |
- status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
|
|
| 40 |
+ status, body, err := request.SockRequest("GET", "/containers/json?all=1", nil, daemonHost())
|
|
| 41 | 41 |
c.Assert(err, checker.IsNil) |
| 42 | 42 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 43 | 43 |
|
| ... | ... |
@@ -57,7 +57,7 @@ func (s *DockerSuite) TestContainerAPIGetAll(c *check.C) {
|
| 57 | 57 |
func (s *DockerSuite) TestContainerAPIGetJSONNoFieldsOmitted(c *check.C) {
|
| 58 | 58 |
dockerCmd(c, "run", "busybox", "true") |
| 59 | 59 |
|
| 60 |
- status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
|
|
| 60 |
+ status, body, err := request.SockRequest("GET", "/containers/json?all=1", nil, daemonHost())
|
|
| 61 | 61 |
c.Assert(err, checker.IsNil) |
| 62 | 62 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 63 | 63 |
|
| ... | ... |
@@ -98,7 +98,7 @@ func (s *DockerSuite) TestContainerAPIPsOmitFields(c *check.C) {
|
| 98 | 98 |
port := 80 |
| 99 | 99 |
runSleepingContainer(c, "--name", name, "--expose", strconv.Itoa(port)) |
| 100 | 100 |
|
| 101 |
- status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
|
|
| 101 |
+ status, body, err := request.SockRequest("GET", "/containers/json?all=1", nil, daemonHost())
|
|
| 102 | 102 |
c.Assert(err, checker.IsNil) |
| 103 | 103 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 104 | 104 |
|
| ... | ... |
@@ -130,7 +130,7 @@ func (s *DockerSuite) TestContainerAPIGetExport(c *check.C) {
|
| 130 | 130 |
name := "exportcontainer" |
| 131 | 131 |
dockerCmd(c, "run", "--name", name, "busybox", "touch", "/test") |
| 132 | 132 |
|
| 133 |
- status, body, err := sockRequest("GET", "/containers/"+name+"/export", nil)
|
|
| 133 |
+ status, body, err := request.SockRequest("GET", "/containers/"+name+"/export", nil, daemonHost())
|
|
| 134 | 134 |
c.Assert(err, checker.IsNil) |
| 135 | 135 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 136 | 136 |
|
| ... | ... |
@@ -154,7 +154,7 @@ func (s *DockerSuite) TestContainerAPIGetChanges(c *check.C) {
|
| 154 | 154 |
name := "changescontainer" |
| 155 | 155 |
dockerCmd(c, "run", "--name", name, "busybox", "rm", "/etc/passwd") |
| 156 | 156 |
|
| 157 |
- status, body, err := sockRequest("GET", "/containers/"+name+"/changes", nil)
|
|
| 157 |
+ status, body, err := request.SockRequest("GET", "/containers/"+name+"/changes", nil, daemonHost())
|
|
| 158 | 158 |
c.Assert(err, checker.IsNil) |
| 159 | 159 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 160 | 160 |
|
| ... | ... |
@@ -187,7 +187,7 @@ func (s *DockerSuite) TestGetContainerStats(c *check.C) {
|
| 187 | 187 |
} |
| 188 | 188 |
bc := make(chan b, 1) |
| 189 | 189 |
go func() {
|
| 190 |
- status, body, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
|
|
| 190 |
+ status, body, err := request.SockRequest("GET", "/containers/"+name+"/stats", nil, daemonHost())
|
|
| 191 | 191 |
bc <- b{status, body, err}
|
| 192 | 192 |
}() |
| 193 | 193 |
|
| ... | ... |
@@ -218,7 +218,7 @@ func (s *DockerSuite) TestGetContainerStatsRmRunning(c *check.C) {
|
| 218 | 218 |
buf := &testutil.ChannelBuffer{make(chan []byte, 1)}
|
| 219 | 219 |
defer buf.Close() |
| 220 | 220 |
|
| 221 |
- _, body, err := sockRequestRaw("GET", "/containers/"+id+"/stats?stream=1", nil, "application/json")
|
|
| 221 |
+ _, body, err := request.SockRequestRaw("GET", "/containers/"+id+"/stats?stream=1", nil, "application/json", daemonHost())
|
|
| 222 | 222 |
c.Assert(err, checker.IsNil) |
| 223 | 223 |
defer body.Close() |
| 224 | 224 |
|
| ... | ... |
@@ -257,7 +257,7 @@ func (s *DockerSuite) TestGetContainerStatsStream(c *check.C) {
|
| 257 | 257 |
} |
| 258 | 258 |
bc := make(chan b, 1) |
| 259 | 259 |
go func() {
|
| 260 |
- status, body, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
|
|
| 260 |
+ status, body, err := request.SockRequest("GET", "/containers/"+name+"/stats", nil, daemonHost())
|
|
| 261 | 261 |
bc <- b{status, body, err}
|
| 262 | 262 |
}() |
| 263 | 263 |
|
| ... | ... |
@@ -293,7 +293,7 @@ func (s *DockerSuite) TestGetContainerStatsNoStream(c *check.C) {
|
| 293 | 293 |
} |
| 294 | 294 |
bc := make(chan b, 1) |
| 295 | 295 |
go func() {
|
| 296 |
- status, body, err := sockRequest("GET", "/containers/"+name+"/stats?stream=0", nil)
|
|
| 296 |
+ status, body, err := request.SockRequest("GET", "/containers/"+name+"/stats?stream=0", nil, daemonHost())
|
|
| 297 | 297 |
bc <- b{status, body, err}
|
| 298 | 298 |
}() |
| 299 | 299 |
|
| ... | ... |
@@ -329,7 +329,7 @@ func (s *DockerSuite) TestGetStoppedContainerStats(c *check.C) {
|
| 329 | 329 |
// We expect an immediate response, but if it's not immediate, the test would hang, so put it in a goroutine |
| 330 | 330 |
// below we'll check this on a timeout. |
| 331 | 331 |
go func() {
|
| 332 |
- resp, body, err := sockRequestRaw("GET", "/containers/"+name+"/stats", nil, "")
|
|
| 332 |
+ resp, body, err := request.SockRequestRaw("GET", "/containers/"+name+"/stats", nil, "", daemonHost())
|
|
| 333 | 333 |
body.Close() |
| 334 | 334 |
chResp <- stats{resp.StatusCode, err}
|
| 335 | 335 |
}() |
| ... | ... |
@@ -350,7 +350,7 @@ func (s *DockerSuite) TestContainerAPIPause(c *check.C) {
|
| 350 | 350 |
out, _ := dockerCmd(c, "run", "-d", "busybox", "sleep", "30") |
| 351 | 351 |
ContainerID := strings.TrimSpace(out) |
| 352 | 352 |
|
| 353 |
- status, _, err := sockRequest("POST", "/containers/"+ContainerID+"/pause", nil)
|
|
| 353 |
+ status, _, err := request.SockRequest("POST", "/containers/"+ContainerID+"/pause", nil, daemonHost())
|
|
| 354 | 354 |
c.Assert(err, checker.IsNil) |
| 355 | 355 |
c.Assert(status, checker.Equals, http.StatusNoContent) |
| 356 | 356 |
|
| ... | ... |
@@ -361,7 +361,7 @@ func (s *DockerSuite) TestContainerAPIPause(c *check.C) {
|
| 361 | 361 |
c.Fatalf("there should be one paused container and not %d", len(pausedContainers))
|
| 362 | 362 |
} |
| 363 | 363 |
|
| 364 |
- status, _, err = sockRequest("POST", "/containers/"+ContainerID+"/unpause", nil)
|
|
| 364 |
+ status, _, err = request.SockRequest("POST", "/containers/"+ContainerID+"/unpause", nil, daemonHost())
|
|
| 365 | 365 |
c.Assert(err, checker.IsNil) |
| 366 | 366 |
c.Assert(status, checker.Equals, http.StatusNoContent) |
| 367 | 367 |
|
| ... | ... |
@@ -381,7 +381,7 @@ func (s *DockerSuite) TestContainerAPITop(c *check.C) {
|
| 381 | 381 |
Processes [][]string |
| 382 | 382 |
} |
| 383 | 383 |
var top topResp |
| 384 |
- status, b, err := sockRequest("GET", "/containers/"+id+"/top?ps_args=aux", nil)
|
|
| 384 |
+ status, b, err := request.SockRequest("GET", "/containers/"+id+"/top?ps_args=aux", nil, daemonHost())
|
|
| 385 | 385 |
c.Assert(err, checker.IsNil) |
| 386 | 386 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 387 | 387 |
c.Assert(json.Unmarshal(b, &top), checker.IsNil) |
| ... | ... |
@@ -406,7 +406,7 @@ func (s *DockerSuite) TestContainerAPITopWindows(c *check.C) {
|
| 406 | 406 |
Processes [][]string |
| 407 | 407 |
} |
| 408 | 408 |
var top topResp |
| 409 |
- status, b, err := sockRequest("GET", "/containers/"+id+"/top", nil)
|
|
| 409 |
+ status, b, err := request.SockRequest("GET", "/containers/"+id+"/top", nil, daemonHost())
|
|
| 410 | 410 |
c.Assert(err, checker.IsNil) |
| 411 | 411 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 412 | 412 |
c.Assert(json.Unmarshal(b, &top), checker.IsNil) |
| ... | ... |
@@ -434,7 +434,7 @@ func (s *DockerSuite) TestContainerAPICommit(c *check.C) {
|
| 434 | 434 |
dockerCmd(c, "run", "--name="+cName, "busybox", "/bin/sh", "-c", "touch /test") |
| 435 | 435 |
|
| 436 | 436 |
name := "testcontainerapicommit" |
| 437 |
- status, b, err := sockRequest("POST", "/commit?repo="+name+"&testtag=tag&container="+cName, nil)
|
|
| 437 |
+ status, b, err := request.SockRequest("POST", "/commit?repo="+name+"&testtag=tag&container="+cName, nil, daemonHost())
|
|
| 438 | 438 |
c.Assert(err, checker.IsNil) |
| 439 | 439 |
c.Assert(status, checker.Equals, http.StatusCreated) |
| 440 | 440 |
|
| ... | ... |
@@ -460,7 +460,7 @@ func (s *DockerSuite) TestContainerAPICommitWithLabelInConfig(c *check.C) {
|
| 460 | 460 |
} |
| 461 | 461 |
|
| 462 | 462 |
name := "testcontainerapicommitwithconfig" |
| 463 |
- status, b, err := sockRequest("POST", "/commit?repo="+name+"&container="+cName, config)
|
|
| 463 |
+ status, b, err := request.SockRequest("POST", "/commit?repo="+name+"&container="+cName, config, daemonHost())
|
|
| 464 | 464 |
c.Assert(err, checker.IsNil) |
| 465 | 465 |
c.Assert(status, checker.Equals, http.StatusCreated) |
| 466 | 466 |
|
| ... | ... |
@@ -502,7 +502,7 @@ func (s *DockerSuite) TestContainerAPIBadPort(c *check.C) {
|
| 502 | 502 |
jsonData := bytes.NewBuffer(nil) |
| 503 | 503 |
json.NewEncoder(jsonData).Encode(config) |
| 504 | 504 |
|
| 505 |
- status, body, err := sockRequest("POST", "/containers/create", config)
|
|
| 505 |
+ status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
|
| 506 | 506 |
c.Assert(err, checker.IsNil) |
| 507 | 507 |
c.Assert(status, checker.Equals, http.StatusInternalServerError) |
| 508 | 508 |
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) {
|
| 514 | 514 |
"Cmd": []string{"/bin/sh", "-c", "touch /test && ls /test"},
|
| 515 | 515 |
} |
| 516 | 516 |
|
| 517 |
- status, b, err := sockRequest("POST", "/containers/create", config)
|
|
| 517 |
+ status, b, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
|
| 518 | 518 |
c.Assert(err, checker.IsNil) |
| 519 | 519 |
c.Assert(status, checker.Equals, http.StatusCreated) |
| 520 | 520 |
|
| ... | ... |
@@ -531,7 +531,7 @@ func (s *DockerSuite) TestContainerAPICreate(c *check.C) {
|
| 531 | 531 |
func (s *DockerSuite) TestContainerAPICreateEmptyConfig(c *check.C) {
|
| 532 | 532 |
config := map[string]interface{}{}
|
| 533 | 533 |
|
| 534 |
- status, body, err := sockRequest("POST", "/containers/create", config)
|
|
| 534 |
+ status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
|
| 535 | 535 |
c.Assert(err, checker.IsNil) |
| 536 | 536 |
c.Assert(status, checker.Equals, http.StatusInternalServerError) |
| 537 | 537 |
|
| ... | ... |
@@ -552,7 +552,7 @@ func (s *DockerSuite) TestContainerAPICreateMultipleNetworksConfig(c *check.C) {
|
| 552 | 552 |
}, |
| 553 | 553 |
} |
| 554 | 554 |
|
| 555 |
- status, body, err := sockRequest("POST", "/containers/create", config)
|
|
| 555 |
+ status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
|
| 556 | 556 |
c.Assert(err, checker.IsNil) |
| 557 | 557 |
c.Assert(status, checker.Equals, http.StatusBadRequest) |
| 558 | 558 |
msg := getErrorMessage(c, body) |
| ... | ... |
@@ -570,14 +570,14 @@ func (s *DockerSuite) TestContainerAPICreateWithHostName(c *check.C) {
|
| 570 | 570 |
"Hostname": hostName, |
| 571 | 571 |
} |
| 572 | 572 |
|
| 573 |
- status, body, err := sockRequest("POST", "/containers/create", config)
|
|
| 573 |
+ status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
|
| 574 | 574 |
c.Assert(err, checker.IsNil) |
| 575 | 575 |
c.Assert(status, checker.Equals, http.StatusCreated) |
| 576 | 576 |
|
| 577 | 577 |
var container containertypes.ContainerCreateCreatedBody |
| 578 | 578 |
c.Assert(json.Unmarshal(body, &container), checker.IsNil) |
| 579 | 579 |
|
| 580 |
- status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
|
|
| 580 |
+ status, body, err = request.SockRequest("GET", "/containers/"+container.ID+"/json", nil, daemonHost())
|
|
| 581 | 581 |
c.Assert(err, checker.IsNil) |
| 582 | 582 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 583 | 583 |
|
| ... | ... |
@@ -593,14 +593,14 @@ func (s *DockerSuite) TestContainerAPICreateWithDomainName(c *check.C) {
|
| 593 | 593 |
"Domainname": domainName, |
| 594 | 594 |
} |
| 595 | 595 |
|
| 596 |
- status, body, err := sockRequest("POST", "/containers/create", config)
|
|
| 596 |
+ status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
|
| 597 | 597 |
c.Assert(err, checker.IsNil) |
| 598 | 598 |
c.Assert(status, checker.Equals, http.StatusCreated) |
| 599 | 599 |
|
| 600 | 600 |
var container containertypes.ContainerCreateCreatedBody |
| 601 | 601 |
c.Assert(json.Unmarshal(body, &container), checker.IsNil) |
| 602 | 602 |
|
| 603 |
- status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
|
|
| 603 |
+ status, body, err = request.SockRequest("GET", "/containers/"+container.ID+"/json", nil, daemonHost())
|
|
| 604 | 604 |
c.Assert(err, checker.IsNil) |
| 605 | 605 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 606 | 606 |
|
| ... | ... |
@@ -628,14 +628,14 @@ func UtilCreateNetworkMode(c *check.C, networkMode string) {
|
| 628 | 628 |
"HostConfig": map[string]interface{}{"NetworkMode": networkMode},
|
| 629 | 629 |
} |
| 630 | 630 |
|
| 631 |
- status, body, err := sockRequest("POST", "/containers/create", config)
|
|
| 631 |
+ status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
|
| 632 | 632 |
c.Assert(err, checker.IsNil) |
| 633 | 633 |
c.Assert(status, checker.Equals, http.StatusCreated) |
| 634 | 634 |
|
| 635 | 635 |
var container containertypes.ContainerCreateCreatedBody |
| 636 | 636 |
c.Assert(json.Unmarshal(body, &container), checker.IsNil) |
| 637 | 637 |
|
| 638 |
- status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
|
|
| 638 |
+ status, body, err = request.SockRequest("GET", "/containers/"+container.ID+"/json", nil, daemonHost())
|
|
| 639 | 639 |
c.Assert(err, checker.IsNil) |
| 640 | 640 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 641 | 641 |
|
| ... | ... |
@@ -653,14 +653,14 @@ func (s *DockerSuite) TestContainerAPICreateWithCpuSharesCpuset(c *check.C) {
|
| 653 | 653 |
"CpusetCpus": "0", |
| 654 | 654 |
} |
| 655 | 655 |
|
| 656 |
- status, body, err := sockRequest("POST", "/containers/create", config)
|
|
| 656 |
+ status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
|
| 657 | 657 |
c.Assert(err, checker.IsNil) |
| 658 | 658 |
c.Assert(status, checker.Equals, http.StatusCreated) |
| 659 | 659 |
|
| 660 | 660 |
var container containertypes.ContainerCreateCreatedBody |
| 661 | 661 |
c.Assert(json.Unmarshal(body, &container), checker.IsNil) |
| 662 | 662 |
|
| 663 |
- status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
|
|
| 663 |
+ status, body, err = request.SockRequest("GET", "/containers/"+container.ID+"/json", nil, daemonHost())
|
|
| 664 | 664 |
c.Assert(err, checker.IsNil) |
| 665 | 665 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 666 | 666 |
|
| ... | ... |
@@ -683,7 +683,7 @@ func (s *DockerSuite) TestContainerAPIVerifyHeader(c *check.C) {
|
| 683 | 683 |
create := func(ct string) (*http.Response, io.ReadCloser, error) {
|
| 684 | 684 |
jsonData := bytes.NewBuffer(nil) |
| 685 | 685 |
c.Assert(json.NewEncoder(jsonData).Encode(config), checker.IsNil) |
| 686 |
- return sockRequestRaw("POST", "/containers/create", jsonData, ct)
|
|
| 686 |
+ return request.SockRequestRaw("POST", "/containers/create", jsonData, ct, daemonHost())
|
|
| 687 | 687 |
} |
| 688 | 688 |
|
| 689 | 689 |
// Try with no content-type |
| ... | ... |
@@ -719,7 +719,7 @@ func (s *DockerSuite) TestContainerAPIInvalidPortSyntax(c *check.C) {
|
| 719 | 719 |
} |
| 720 | 720 |
}` |
| 721 | 721 |
|
| 722 |
- res, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
|
| 722 |
+ res, body, err := request.SockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json", daemonHost())
|
|
| 723 | 723 |
c.Assert(err, checker.IsNil) |
| 724 | 724 |
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError) |
| 725 | 725 |
|
| ... | ... |
@@ -739,7 +739,7 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyInvalidPolicyName(c *check.C) |
| 739 | 739 |
} |
| 740 | 740 |
}` |
| 741 | 741 |
|
| 742 |
- res, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
|
| 742 |
+ res, body, err := request.SockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json", daemonHost())
|
|
| 743 | 743 |
c.Assert(err, checker.IsNil) |
| 744 | 744 |
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError) |
| 745 | 745 |
|
| ... | ... |
@@ -759,7 +759,7 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyRetryMismatch(c *check.C) {
|
| 759 | 759 |
} |
| 760 | 760 |
}` |
| 761 | 761 |
|
| 762 |
- res, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
|
| 762 |
+ res, body, err := request.SockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json", daemonHost())
|
|
| 763 | 763 |
c.Assert(err, checker.IsNil) |
| 764 | 764 |
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError) |
| 765 | 765 |
|
| ... | ... |
@@ -779,7 +779,7 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyNegativeRetryCount(c *check.C |
| 779 | 779 |
} |
| 780 | 780 |
}` |
| 781 | 781 |
|
| 782 |
- res, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
|
| 782 |
+ res, body, err := request.SockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json", daemonHost())
|
|
| 783 | 783 |
c.Assert(err, checker.IsNil) |
| 784 | 784 |
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError) |
| 785 | 785 |
|
| ... | ... |
@@ -799,7 +799,7 @@ func (s *DockerSuite) TestContainerAPIRestartPolicyDefaultRetryCount(c *check.C) |
| 799 | 799 |
} |
| 800 | 800 |
}` |
| 801 | 801 |
|
| 802 |
- res, _, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
|
| 802 |
+ res, _, err := request.SockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json", daemonHost())
|
|
| 803 | 803 |
c.Assert(err, checker.IsNil) |
| 804 | 804 |
c.Assert(res.StatusCode, checker.Equals, http.StatusCreated) |
| 805 | 805 |
} |
| ... | ... |
@@ -830,7 +830,7 @@ func (s *DockerSuite) TestContainerAPIPostCreateNull(c *check.C) {
|
| 830 | 830 |
"NetworkDisabled":false, |
| 831 | 831 |
"OnBuild":null}` |
| 832 | 832 |
|
| 833 |
- res, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
|
| 833 |
+ res, body, err := request.SockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json", daemonHost())
|
|
| 834 | 834 |
c.Assert(err, checker.IsNil) |
| 835 | 835 |
c.Assert(res.StatusCode, checker.Equals, http.StatusCreated) |
| 836 | 836 |
|
| ... | ... |
@@ -861,7 +861,7 @@ func (s *DockerSuite) TestCreateWithTooLowMemoryLimit(c *check.C) {
|
| 861 | 861 |
"Memory": 524287 |
| 862 | 862 |
}` |
| 863 | 863 |
|
| 864 |
- res, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
|
| 864 |
+ res, body, err := request.SockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json", daemonHost())
|
|
| 865 | 865 |
c.Assert(err, checker.IsNil) |
| 866 | 866 |
b, err2 := testutil.ReadBody(body) |
| 867 | 867 |
c.Assert(err2, checker.IsNil) |
| ... | ... |
@@ -875,7 +875,7 @@ func (s *DockerSuite) TestContainerAPIRename(c *check.C) {
|
| 875 | 875 |
|
| 876 | 876 |
containerID := strings.TrimSpace(out) |
| 877 | 877 |
newName := "TestContainerAPIRenameNew" |
| 878 |
- statusCode, _, err := sockRequest("POST", "/containers/"+containerID+"/rename?name="+newName, nil)
|
|
| 878 |
+ statusCode, _, err := request.SockRequest("POST", "/containers/"+containerID+"/rename?name="+newName, nil, daemonHost())
|
|
| 879 | 879 |
c.Assert(err, checker.IsNil) |
| 880 | 880 |
// 204 No Content is expected, not 200 |
| 881 | 881 |
c.Assert(statusCode, checker.Equals, http.StatusNoContent) |
| ... | ... |
@@ -888,7 +888,7 @@ func (s *DockerSuite) TestContainerAPIKill(c *check.C) {
|
| 888 | 888 |
name := "test-api-kill" |
| 889 | 889 |
runSleepingContainer(c, "-i", "--name", name) |
| 890 | 890 |
|
| 891 |
- status, _, err := sockRequest("POST", "/containers/"+name+"/kill", nil)
|
|
| 891 |
+ status, _, err := request.SockRequest("POST", "/containers/"+name+"/kill", nil, daemonHost())
|
|
| 892 | 892 |
c.Assert(err, checker.IsNil) |
| 893 | 893 |
c.Assert(status, checker.Equals, http.StatusNoContent) |
| 894 | 894 |
|
| ... | ... |
@@ -900,7 +900,7 @@ func (s *DockerSuite) TestContainerAPIRestart(c *check.C) {
|
| 900 | 900 |
name := "test-api-restart" |
| 901 | 901 |
runSleepingContainer(c, "-di", "--name", name) |
| 902 | 902 |
|
| 903 |
- status, _, err := sockRequest("POST", "/containers/"+name+"/restart?t=1", nil)
|
|
| 903 |
+ status, _, err := request.SockRequest("POST", "/containers/"+name+"/restart?t=1", nil, daemonHost())
|
|
| 904 | 904 |
c.Assert(err, checker.IsNil) |
| 905 | 905 |
c.Assert(status, checker.Equals, http.StatusNoContent) |
| 906 | 906 |
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) {
|
| 912 | 912 |
id := strings.TrimSpace(out) |
| 913 | 913 |
c.Assert(waitRun(id), checker.IsNil) |
| 914 | 914 |
|
| 915 |
- status, _, err := sockRequest("POST", "/containers/"+name+"/restart", nil)
|
|
| 915 |
+ status, _, err := request.SockRequest("POST", "/containers/"+name+"/restart", nil, daemonHost())
|
|
| 916 | 916 |
c.Assert(err, checker.IsNil) |
| 917 | 917 |
c.Assert(status, checker.Equals, http.StatusNoContent) |
| 918 | 918 |
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) {
|
| 926 | 926 |
"OpenStdin": true, |
| 927 | 927 |
} |
| 928 | 928 |
|
| 929 |
- status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
|
|
| 929 |
+ status, _, err := request.SockRequest("POST", "/containers/create?name="+name, config, daemonHost())
|
|
| 930 | 930 |
c.Assert(err, checker.IsNil) |
| 931 | 931 |
c.Assert(status, checker.Equals, http.StatusCreated) |
| 932 | 932 |
|
| 933 |
- status, _, err = sockRequest("POST", "/containers/"+name+"/start", nil)
|
|
| 933 |
+ status, _, err = request.SockRequest("POST", "/containers/"+name+"/start", nil, daemonHost())
|
|
| 934 | 934 |
c.Assert(err, checker.IsNil) |
| 935 | 935 |
c.Assert(status, checker.Equals, http.StatusNoContent) |
| 936 | 936 |
|
| 937 | 937 |
// second call to start should give 304 |
| 938 |
- status, _, err = sockRequest("POST", "/containers/"+name+"/start", nil)
|
|
| 938 |
+ status, _, err = request.SockRequest("POST", "/containers/"+name+"/start", nil, daemonHost())
|
|
| 939 | 939 |
c.Assert(err, checker.IsNil) |
| 940 | 940 |
|
| 941 | 941 |
// TODO(tibor): figure out why this doesn't work on windows |
| ... | ... |
@@ -948,13 +948,13 @@ func (s *DockerSuite) TestContainerAPIStop(c *check.C) {
|
| 948 | 948 |
name := "test-api-stop" |
| 949 | 949 |
runSleepingContainer(c, "-i", "--name", name) |
| 950 | 950 |
|
| 951 |
- status, _, err := sockRequest("POST", "/containers/"+name+"/stop?t=30", nil)
|
|
| 951 |
+ status, _, err := request.SockRequest("POST", "/containers/"+name+"/stop?t=30", nil, daemonHost())
|
|
| 952 | 952 |
c.Assert(err, checker.IsNil) |
| 953 | 953 |
c.Assert(status, checker.Equals, http.StatusNoContent) |
| 954 | 954 |
c.Assert(waitInspect(name, "{{ .State.Running }}", "false", 60*time.Second), checker.IsNil)
|
| 955 | 955 |
|
| 956 | 956 |
// second call to start should give 304 |
| 957 |
- status, _, err = sockRequest("POST", "/containers/"+name+"/stop?t=30", nil)
|
|
| 957 |
+ status, _, err = request.SockRequest("POST", "/containers/"+name+"/stop?t=30", nil, daemonHost())
|
|
| 958 | 958 |
c.Assert(err, checker.IsNil) |
| 959 | 959 |
c.Assert(status, checker.Equals, http.StatusNotModified) |
| 960 | 960 |
} |
| ... | ... |
@@ -968,7 +968,7 @@ func (s *DockerSuite) TestContainerAPIWait(c *check.C) {
|
| 968 | 968 |
} |
| 969 | 969 |
dockerCmd(c, "run", "--name", name, "busybox", sleepCmd, "2") |
| 970 | 970 |
|
| 971 |
- status, body, err := sockRequest("POST", "/containers/"+name+"/wait", nil)
|
|
| 971 |
+ status, body, err := request.SockRequest("POST", "/containers/"+name+"/wait", nil, daemonHost())
|
|
| 972 | 972 |
c.Assert(err, checker.IsNil) |
| 973 | 973 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 974 | 974 |
c.Assert(waitInspect(name, "{{ .State.Running }}", "false", 60*time.Second), checker.IsNil)
|
| ... | ... |
@@ -986,7 +986,7 @@ func (s *DockerSuite) TestContainerAPICopyNotExistsAnyMore(c *check.C) {
|
| 986 | 986 |
Resource: "/test.txt", |
| 987 | 987 |
} |
| 988 | 988 |
|
| 989 |
- status, _, err := sockRequest("POST", "/containers/"+name+"/copy", postData)
|
|
| 989 |
+ status, _, err := request.SockRequest("POST", "/containers/"+name+"/copy", postData, daemonHost())
|
|
| 990 | 990 |
c.Assert(err, checker.IsNil) |
| 991 | 991 |
c.Assert(status, checker.Equals, http.StatusNotFound) |
| 992 | 992 |
} |
| ... | ... |
@@ -1000,7 +1000,7 @@ func (s *DockerSuite) TestContainerAPICopyPre124(c *check.C) {
|
| 1000 | 1000 |
Resource: "/test.txt", |
| 1001 | 1001 |
} |
| 1002 | 1002 |
|
| 1003 |
- status, body, err := sockRequest("POST", "/v1.23/containers/"+name+"/copy", postData)
|
|
| 1003 |
+ status, body, err := request.SockRequest("POST", "/v1.23/containers/"+name+"/copy", postData, daemonHost())
|
|
| 1004 | 1004 |
c.Assert(err, checker.IsNil) |
| 1005 | 1005 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 1006 | 1006 |
|
| ... | ... |
@@ -1030,7 +1030,7 @@ func (s *DockerSuite) TestContainerAPICopyResourcePathEmptyPr124(c *check.C) {
|
| 1030 | 1030 |
Resource: "", |
| 1031 | 1031 |
} |
| 1032 | 1032 |
|
| 1033 |
- status, body, err := sockRequest("POST", "/v1.23/containers/"+name+"/copy", postData)
|
|
| 1033 |
+ status, body, err := request.SockRequest("POST", "/v1.23/containers/"+name+"/copy", postData, daemonHost())
|
|
| 1034 | 1034 |
c.Assert(err, checker.IsNil) |
| 1035 | 1035 |
c.Assert(status, checker.Equals, http.StatusInternalServerError) |
| 1036 | 1036 |
c.Assert(string(body), checker.Matches, "Path cannot be empty\n") |
| ... | ... |
@@ -1045,7 +1045,7 @@ func (s *DockerSuite) TestContainerAPICopyResourcePathNotFoundPre124(c *check.C) |
| 1045 | 1045 |
Resource: "/notexist", |
| 1046 | 1046 |
} |
| 1047 | 1047 |
|
| 1048 |
- status, body, err := sockRequest("POST", "/v1.23/containers/"+name+"/copy", postData)
|
|
| 1048 |
+ status, body, err := request.SockRequest("POST", "/v1.23/containers/"+name+"/copy", postData, daemonHost())
|
|
| 1049 | 1049 |
c.Assert(err, checker.IsNil) |
| 1050 | 1050 |
c.Assert(status, checker.Equals, http.StatusInternalServerError) |
| 1051 | 1051 |
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) {
|
| 1057 | 1057 |
Resource: "/something", |
| 1058 | 1058 |
} |
| 1059 | 1059 |
|
| 1060 |
- status, _, err := sockRequest("POST", "/v1.23/containers/notexists/copy", postData)
|
|
| 1060 |
+ status, _, err := request.SockRequest("POST", "/v1.23/containers/notexists/copy", postData, daemonHost())
|
|
| 1061 | 1061 |
c.Assert(err, checker.IsNil) |
| 1062 | 1062 |
c.Assert(status, checker.Equals, http.StatusNotFound) |
| 1063 | 1063 |
} |
| ... | ... |
@@ -1070,13 +1070,13 @@ func (s *DockerSuite) TestContainerAPIDelete(c *check.C) {
|
| 1070 | 1070 |
|
| 1071 | 1071 |
dockerCmd(c, "stop", id) |
| 1072 | 1072 |
|
| 1073 |
- status, _, err := sockRequest("DELETE", "/containers/"+id, nil)
|
|
| 1073 |
+ status, _, err := request.SockRequest("DELETE", "/containers/"+id, nil, daemonHost())
|
|
| 1074 | 1074 |
c.Assert(err, checker.IsNil) |
| 1075 | 1075 |
c.Assert(status, checker.Equals, http.StatusNoContent) |
| 1076 | 1076 |
} |
| 1077 | 1077 |
|
| 1078 | 1078 |
func (s *DockerSuite) TestContainerAPIDeleteNotExist(c *check.C) {
|
| 1079 |
- status, body, err := sockRequest("DELETE", "/containers/doesnotexist", nil)
|
|
| 1079 |
+ status, body, err := request.SockRequest("DELETE", "/containers/doesnotexist", nil, daemonHost())
|
|
| 1080 | 1080 |
c.Assert(err, checker.IsNil) |
| 1081 | 1081 |
c.Assert(status, checker.Equals, http.StatusNotFound) |
| 1082 | 1082 |
c.Assert(getErrorMessage(c, body), checker.Matches, "No such container: doesnotexist") |
| ... | ... |
@@ -1088,7 +1088,7 @@ func (s *DockerSuite) TestContainerAPIDeleteForce(c *check.C) {
|
| 1088 | 1088 |
id := strings.TrimSpace(out) |
| 1089 | 1089 |
c.Assert(waitRun(id), checker.IsNil) |
| 1090 | 1090 |
|
| 1091 |
- status, _, err := sockRequest("DELETE", "/containers/"+id+"?force=1", nil)
|
|
| 1091 |
+ status, _, err := request.SockRequest("DELETE", "/containers/"+id+"?force=1", nil, daemonHost())
|
|
| 1092 | 1092 |
c.Assert(err, checker.IsNil) |
| 1093 | 1093 |
c.Assert(status, checker.Equals, http.StatusNoContent) |
| 1094 | 1094 |
} |
| ... | ... |
@@ -1109,7 +1109,7 @@ func (s *DockerSuite) TestContainerAPIDeleteRemoveLinks(c *check.C) {
|
| 1109 | 1109 |
links := inspectFieldJSON(c, id2, "HostConfig.Links") |
| 1110 | 1110 |
c.Assert(links, checker.Equals, "[\"/tlink1:/tlink2/tlink1\"]", check.Commentf("expected to have links between containers"))
|
| 1111 | 1111 |
|
| 1112 |
- status, b, err := sockRequest("DELETE", "/containers/tlink2/tlink1?link=1", nil)
|
|
| 1112 |
+ status, b, err := request.SockRequest("DELETE", "/containers/tlink2/tlink1?link=1", nil, daemonHost())
|
|
| 1113 | 1113 |
c.Assert(err, check.IsNil) |
| 1114 | 1114 |
c.Assert(status, check.Equals, http.StatusNoContent, check.Commentf(string(b))) |
| 1115 | 1115 |
|
| ... | ... |
@@ -1123,7 +1123,7 @@ func (s *DockerSuite) TestContainerAPIDeleteConflict(c *check.C) {
|
| 1123 | 1123 |
id := strings.TrimSpace(out) |
| 1124 | 1124 |
c.Assert(waitRun(id), checker.IsNil) |
| 1125 | 1125 |
|
| 1126 |
- status, _, err := sockRequest("DELETE", "/containers/"+id, nil)
|
|
| 1126 |
+ status, _, err := request.SockRequest("DELETE", "/containers/"+id, nil, daemonHost())
|
|
| 1127 | 1127 |
c.Assert(err, checker.IsNil) |
| 1128 | 1128 |
c.Assert(status, checker.Equals, http.StatusConflict) |
| 1129 | 1129 |
} |
| ... | ... |
@@ -1145,7 +1145,7 @@ func (s *DockerSuite) TestContainerAPIDeleteRemoveVolume(c *check.C) {
|
| 1145 | 1145 |
_, err = os.Stat(source) |
| 1146 | 1146 |
c.Assert(err, checker.IsNil) |
| 1147 | 1147 |
|
| 1148 |
- status, _, err := sockRequest("DELETE", "/containers/"+id+"?v=1&force=1", nil)
|
|
| 1148 |
+ status, _, err := request.SockRequest("DELETE", "/containers/"+id+"?v=1&force=1", nil, daemonHost())
|
|
| 1149 | 1149 |
c.Assert(err, checker.IsNil) |
| 1150 | 1150 |
c.Assert(status, checker.Equals, http.StatusNoContent) |
| 1151 | 1151 |
_, err = os.Stat(source) |
| ... | ... |
@@ -1154,30 +1154,21 @@ func (s *DockerSuite) TestContainerAPIDeleteRemoveVolume(c *check.C) {
|
| 1154 | 1154 |
|
| 1155 | 1155 |
// Regression test for https://github.com/docker/docker/issues/6231 |
| 1156 | 1156 |
func (s *DockerSuite) TestContainerAPIChunkedEncoding(c *check.C) {
|
| 1157 |
- conn, err := sockConn(time.Duration(10*time.Second), "") |
|
| 1158 |
- c.Assert(err, checker.IsNil) |
|
| 1159 |
- client := httputil.NewClientConn(conn, nil) |
|
| 1160 |
- defer client.Close() |
|
| 1161 | 1157 |
|
| 1162 | 1158 |
config := map[string]interface{}{
|
| 1163 | 1159 |
"Image": "busybox", |
| 1164 | 1160 |
"Cmd": append([]string{"/bin/sh", "-c"}, sleepCommandForDaemonPlatform()...),
|
| 1165 | 1161 |
"OpenStdin": true, |
| 1166 | 1162 |
} |
| 1167 |
- b, err := json.Marshal(config) |
|
| 1168 |
- c.Assert(err, checker.IsNil) |
|
| 1169 | 1163 |
|
| 1170 |
- req, err := http.NewRequest("POST", "/containers/create", bytes.NewBuffer(b))
|
|
| 1171 |
- c.Assert(err, checker.IsNil) |
|
| 1172 |
- req.Header.Set("Content-Type", "application/json")
|
|
| 1173 |
- // This is a cheat to make the http request do chunked encoding |
|
| 1174 |
- // Otherwise (just setting the Content-Encoding to chunked) net/http will overwrite |
|
| 1175 |
- // https://golang.org/src/pkg/net/http/request.go?s=11980:12172 |
|
| 1176 |
- req.ContentLength = -1 |
|
| 1177 |
- |
|
| 1178 |
- resp, err := client.Do(req) |
|
| 1164 |
+ resp, _, err := request.Post(daemonHost(), "/containers/create", request.JSONBody(config), func(req *http.Request) error {
|
|
| 1165 |
+ // This is a cheat to make the http request do chunked encoding |
|
| 1166 |
+ // Otherwise (just setting the Content-Encoding to chunked) net/http will overwrite |
|
| 1167 |
+ // https://golang.org/src/pkg/net/http/request.go?s=11980:12172 |
|
| 1168 |
+ req.ContentLength = -1 |
|
| 1169 |
+ return nil |
|
| 1170 |
+ }) |
|
| 1179 | 1171 |
c.Assert(err, checker.IsNil, check.Commentf("error creating container with chunked encoding"))
|
| 1180 |
- resp.Body.Close() |
|
| 1181 | 1172 |
c.Assert(resp.StatusCode, checker.Equals, http.StatusCreated) |
| 1182 | 1173 |
} |
| 1183 | 1174 |
|
| ... | ... |
@@ -1187,7 +1178,7 @@ func (s *DockerSuite) TestContainerAPIPostContainerStop(c *check.C) {
|
| 1187 | 1187 |
containerID := strings.TrimSpace(out) |
| 1188 | 1188 |
c.Assert(waitRun(containerID), checker.IsNil) |
| 1189 | 1189 |
|
| 1190 |
- statusCode, _, err := sockRequest("POST", "/containers/"+containerID+"/stop", nil)
|
|
| 1190 |
+ statusCode, _, err := request.SockRequest("POST", "/containers/"+containerID+"/stop", nil, daemonHost())
|
|
| 1191 | 1191 |
c.Assert(err, checker.IsNil) |
| 1192 | 1192 |
// 204 No Content is expected, not 200 |
| 1193 | 1193 |
c.Assert(statusCode, checker.Equals, http.StatusNoContent) |
| ... | ... |
@@ -1201,7 +1192,7 @@ func (s *DockerSuite) TestPostContainerAPICreateWithStringOrSliceEntrypoint(c *c |
| 1201 | 1201 |
Entrypoint string |
| 1202 | 1202 |
Cmd []string |
| 1203 | 1203 |
}{"busybox", "echo", []string{"hello", "world"}}
|
| 1204 |
- _, _, err := sockRequest("POST", "/containers/create?name=echotest", config)
|
|
| 1204 |
+ _, _, err := request.SockRequest("POST", "/containers/create?name=echotest", config, daemonHost())
|
|
| 1205 | 1205 |
c.Assert(err, checker.IsNil) |
| 1206 | 1206 |
out, _ := dockerCmd(c, "start", "-a", "echotest") |
| 1207 | 1207 |
c.Assert(strings.TrimSpace(out), checker.Equals, "hello world") |
| ... | ... |
@@ -1211,7 +1202,7 @@ func (s *DockerSuite) TestPostContainerAPICreateWithStringOrSliceEntrypoint(c *c |
| 1211 | 1211 |
Entrypoint []string |
| 1212 | 1212 |
Cmd []string |
| 1213 | 1213 |
}{"busybox", []string{"echo"}, []string{"hello", "world"}}
|
| 1214 |
- _, _, err = sockRequest("POST", "/containers/create?name=echotest2", config2)
|
|
| 1214 |
+ _, _, err = request.SockRequest("POST", "/containers/create?name=echotest2", config2, daemonHost())
|
|
| 1215 | 1215 |
c.Assert(err, checker.IsNil) |
| 1216 | 1216 |
out, _ = dockerCmd(c, "start", "-a", "echotest2") |
| 1217 | 1217 |
c.Assert(strings.TrimSpace(out), checker.Equals, "hello world") |
| ... | ... |
@@ -1224,7 +1215,7 @@ func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCmd(c *check.C) {
|
| 1224 | 1224 |
Entrypoint string |
| 1225 | 1225 |
Cmd string |
| 1226 | 1226 |
}{"busybox", "echo", "hello world"}
|
| 1227 |
- _, _, err := sockRequest("POST", "/containers/create?name=echotest", config)
|
|
| 1227 |
+ _, _, err := request.SockRequest("POST", "/containers/create?name=echotest", config, daemonHost())
|
|
| 1228 | 1228 |
c.Assert(err, checker.IsNil) |
| 1229 | 1229 |
out, _ := dockerCmd(c, "start", "-a", "echotest") |
| 1230 | 1230 |
c.Assert(strings.TrimSpace(out), checker.Equals, "hello world") |
| ... | ... |
@@ -1233,7 +1224,7 @@ func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCmd(c *check.C) {
|
| 1233 | 1233 |
Image string |
| 1234 | 1234 |
Cmd []string |
| 1235 | 1235 |
}{"busybox", []string{"echo", "hello", "world"}}
|
| 1236 |
- _, _, err = sockRequest("POST", "/containers/create?name=echotest2", config2)
|
|
| 1236 |
+ _, _, err = request.SockRequest("POST", "/containers/create?name=echotest2", config2, daemonHost())
|
|
| 1237 | 1237 |
c.Assert(err, checker.IsNil) |
| 1238 | 1238 |
out, _ = dockerCmd(c, "start", "-a", "echotest2") |
| 1239 | 1239 |
c.Assert(strings.TrimSpace(out), checker.Equals, "hello world") |
| ... | ... |
@@ -1248,7 +1239,7 @@ func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCapAddDrop(c *che |
| 1248 | 1248 |
CapAdd string |
| 1249 | 1249 |
CapDrop string |
| 1250 | 1250 |
}{"busybox", "NET_ADMIN", "SYS_ADMIN"}
|
| 1251 |
- status, _, err := sockRequest("POST", "/containers/create?name=capaddtest0", config)
|
|
| 1251 |
+ status, _, err := request.SockRequest("POST", "/containers/create?name=capaddtest0", config, daemonHost())
|
|
| 1252 | 1252 |
c.Assert(err, checker.IsNil) |
| 1253 | 1253 |
c.Assert(status, checker.Equals, http.StatusCreated) |
| 1254 | 1254 |
|
| ... | ... |
@@ -1257,7 +1248,7 @@ func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCapAddDrop(c *che |
| 1257 | 1257 |
CapAdd []string |
| 1258 | 1258 |
CapDrop []string |
| 1259 | 1259 |
}{"busybox", []string{"NET_ADMIN", "SYS_ADMIN"}, []string{"SETGID"}}
|
| 1260 |
- status, _, err = sockRequest("POST", "/containers/create?name=capaddtest1", config2)
|
|
| 1260 |
+ status, _, err = request.SockRequest("POST", "/containers/create?name=capaddtest1", config2, daemonHost())
|
|
| 1261 | 1261 |
c.Assert(err, checker.IsNil) |
| 1262 | 1262 |
c.Assert(status, checker.Equals, http.StatusCreated) |
| 1263 | 1263 |
} |
| ... | ... |
@@ -1268,7 +1259,7 @@ func (s *DockerSuite) TestContainerAPICreateNoHostConfig118(c *check.C) {
|
| 1268 | 1268 |
config := struct {
|
| 1269 | 1269 |
Image string |
| 1270 | 1270 |
}{"busybox"}
|
| 1271 |
- status, _, err := sockRequest("POST", "/v1.18/containers/create", config)
|
|
| 1271 |
+ status, _, err := request.SockRequest("POST", "/v1.18/containers/create", config, daemonHost())
|
|
| 1272 | 1272 |
c.Assert(err, checker.IsNil) |
| 1273 | 1273 |
c.Assert(status, checker.Equals, http.StatusCreated) |
| 1274 | 1274 |
} |
| ... | ... |
@@ -1300,7 +1291,7 @@ func (s *DockerSuite) TestPutContainerArchiveErrSymlinkInVolumeToReadOnlyRootfs( |
| 1300 | 1300 |
query.Set("path", "/vol2/symlinkToAbsDir")
|
| 1301 | 1301 |
urlPath := fmt.Sprintf("/v1.20/containers/%s/archive?%s", cID, query.Encode())
|
| 1302 | 1302 |
|
| 1303 |
- statusCode, body, err := sockRequest("PUT", urlPath, nil)
|
|
| 1303 |
+ statusCode, body, err := request.SockRequest("PUT", urlPath, nil, daemonHost())
|
|
| 1304 | 1304 |
c.Assert(err, checker.IsNil) |
| 1305 | 1305 |
|
| 1306 | 1306 |
if !isCpCannotCopyReadOnly(fmt.Errorf(string(body))) {
|
| ... | ... |
@@ -1309,7 +1300,7 @@ func (s *DockerSuite) TestPutContainerArchiveErrSymlinkInVolumeToReadOnlyRootfs( |
| 1309 | 1309 |
} |
| 1310 | 1310 |
|
| 1311 | 1311 |
func (s *DockerSuite) TestContainerAPIGetContainersJSONEmpty(c *check.C) {
|
| 1312 |
- status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
|
|
| 1312 |
+ status, body, err := request.SockRequest("GET", "/containers/json?all=1", nil, daemonHost())
|
|
| 1313 | 1313 |
c.Assert(err, checker.IsNil) |
| 1314 | 1314 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 1315 | 1315 |
c.Assert(string(body), checker.Equals, "[]\n") |
| ... | ... |
@@ -1324,7 +1315,7 @@ func (s *DockerSuite) TestPostContainersCreateWithWrongCpusetValues(c *check.C) |
| 1324 | 1324 |
CpusetCpus string |
| 1325 | 1325 |
}{"busybox", "1-42,,"}
|
| 1326 | 1326 |
name := "wrong-cpuset-cpus" |
| 1327 |
- status, body, err := sockRequest("POST", "/containers/create?name="+name, c1)
|
|
| 1327 |
+ status, body, err := request.SockRequest("POST", "/containers/create?name="+name, c1, daemonHost())
|
|
| 1328 | 1328 |
c.Assert(err, checker.IsNil) |
| 1329 | 1329 |
c.Assert(status, checker.Equals, http.StatusInternalServerError) |
| 1330 | 1330 |
expected := "Invalid value 1-42,, for cpuset cpus" |
| ... | ... |
@@ -1335,7 +1326,7 @@ func (s *DockerSuite) TestPostContainersCreateWithWrongCpusetValues(c *check.C) |
| 1335 | 1335 |
CpusetMems string |
| 1336 | 1336 |
}{"busybox", "42-3,1--"}
|
| 1337 | 1337 |
name = "wrong-cpuset-mems" |
| 1338 |
- status, body, err = sockRequest("POST", "/containers/create?name="+name, c2)
|
|
| 1338 |
+ status, body, err = request.SockRequest("POST", "/containers/create?name="+name, c2, daemonHost())
|
|
| 1339 | 1339 |
c.Assert(err, checker.IsNil) |
| 1340 | 1340 |
c.Assert(status, checker.Equals, http.StatusInternalServerError) |
| 1341 | 1341 |
expected = "Invalid value 42-3,1-- for cpuset mems" |
| ... | ... |
@@ -1350,7 +1341,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeNegative(c *check.C) {
|
| 1350 | 1350 |
"HostConfig": map[string]interface{}{"ShmSize": -1},
|
| 1351 | 1351 |
} |
| 1352 | 1352 |
|
| 1353 |
- status, body, err := sockRequest("POST", "/containers/create", config)
|
|
| 1353 |
+ status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
|
| 1354 | 1354 |
c.Assert(err, check.IsNil) |
| 1355 | 1355 |
c.Assert(status, check.Equals, http.StatusInternalServerError) |
| 1356 | 1356 |
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. |
| 1365 | 1365 |
"Cmd": "mount", |
| 1366 | 1366 |
} |
| 1367 | 1367 |
|
| 1368 |
- status, body, err := sockRequest("POST", "/containers/create", config)
|
|
| 1368 |
+ status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
|
| 1369 | 1369 |
c.Assert(err, check.IsNil) |
| 1370 | 1370 |
c.Assert(status, check.Equals, http.StatusCreated) |
| 1371 | 1371 |
|
| 1372 | 1372 |
var container containertypes.ContainerCreateCreatedBody |
| 1373 | 1373 |
c.Assert(json.Unmarshal(body, &container), check.IsNil) |
| 1374 | 1374 |
|
| 1375 |
- status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
|
|
| 1375 |
+ status, body, err = request.SockRequest("GET", "/containers/"+container.ID+"/json", nil, daemonHost())
|
|
| 1376 | 1376 |
c.Assert(err, check.IsNil) |
| 1377 | 1377 |
c.Assert(status, check.Equals, http.StatusOK) |
| 1378 | 1378 |
|
| ... | ... |
@@ -1397,14 +1388,14 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeOmitted(c *check.C) {
|
| 1397 | 1397 |
"Cmd": "mount", |
| 1398 | 1398 |
} |
| 1399 | 1399 |
|
| 1400 |
- status, body, err := sockRequest("POST", "/containers/create", config)
|
|
| 1400 |
+ status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
|
| 1401 | 1401 |
c.Assert(err, check.IsNil) |
| 1402 | 1402 |
c.Assert(status, check.Equals, http.StatusCreated) |
| 1403 | 1403 |
|
| 1404 | 1404 |
var container containertypes.ContainerCreateCreatedBody |
| 1405 | 1405 |
c.Assert(json.Unmarshal(body, &container), check.IsNil) |
| 1406 | 1406 |
|
| 1407 |
- status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
|
|
| 1407 |
+ status, body, err = request.SockRequest("GET", "/containers/"+container.ID+"/json", nil, daemonHost())
|
|
| 1408 | 1408 |
c.Assert(err, check.IsNil) |
| 1409 | 1409 |
c.Assert(status, check.Equals, http.StatusOK) |
| 1410 | 1410 |
|
| ... | ... |
@@ -1429,14 +1420,14 @@ func (s *DockerSuite) TestPostContainersCreateWithShmSize(c *check.C) {
|
| 1429 | 1429 |
"HostConfig": map[string]interface{}{"ShmSize": 1073741824},
|
| 1430 | 1430 |
} |
| 1431 | 1431 |
|
| 1432 |
- status, body, err := sockRequest("POST", "/containers/create", config)
|
|
| 1432 |
+ status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
|
| 1433 | 1433 |
c.Assert(err, check.IsNil) |
| 1434 | 1434 |
c.Assert(status, check.Equals, http.StatusCreated) |
| 1435 | 1435 |
|
| 1436 | 1436 |
var container containertypes.ContainerCreateCreatedBody |
| 1437 | 1437 |
c.Assert(json.Unmarshal(body, &container), check.IsNil) |
| 1438 | 1438 |
|
| 1439 |
- status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
|
|
| 1439 |
+ status, body, err = request.SockRequest("GET", "/containers/"+container.ID+"/json", nil, daemonHost())
|
|
| 1440 | 1440 |
c.Assert(err, check.IsNil) |
| 1441 | 1441 |
c.Assert(status, check.Equals, http.StatusOK) |
| 1442 | 1442 |
|
| ... | ... |
@@ -1459,14 +1450,14 @@ func (s *DockerSuite) TestPostContainersCreateMemorySwappinessHostConfigOmitted( |
| 1459 | 1459 |
"Image": "busybox", |
| 1460 | 1460 |
} |
| 1461 | 1461 |
|
| 1462 |
- status, body, err := sockRequest("POST", "/containers/create", config)
|
|
| 1462 |
+ status, body, err := request.SockRequest("POST", "/containers/create", config, daemonHost())
|
|
| 1463 | 1463 |
c.Assert(err, check.IsNil) |
| 1464 | 1464 |
c.Assert(status, check.Equals, http.StatusCreated) |
| 1465 | 1465 |
|
| 1466 | 1466 |
var container containertypes.ContainerCreateCreatedBody |
| 1467 | 1467 |
c.Assert(json.Unmarshal(body, &container), check.IsNil) |
| 1468 | 1468 |
|
| 1469 |
- status, body, err = sockRequest("GET", "/containers/"+container.ID+"/json", nil)
|
|
| 1469 |
+ status, body, err = request.SockRequest("GET", "/containers/"+container.ID+"/json", nil, daemonHost())
|
|
| 1470 | 1470 |
c.Assert(err, check.IsNil) |
| 1471 | 1471 |
c.Assert(status, check.Equals, http.StatusOK) |
| 1472 | 1472 |
|
| ... | ... |
@@ -1486,7 +1477,7 @@ func (s *DockerSuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *che |
| 1486 | 1486 |
OomScoreAdj int |
| 1487 | 1487 |
}{"busybox", 1001}
|
| 1488 | 1488 |
name := "oomscoreadj-over" |
| 1489 |
- status, b, err := sockRequest("POST", "/containers/create?name="+name, config)
|
|
| 1489 |
+ status, b, err := request.SockRequest("POST", "/containers/create?name="+name, config, daemonHost())
|
|
| 1490 | 1490 |
c.Assert(err, check.IsNil) |
| 1491 | 1491 |
c.Assert(status, check.Equals, http.StatusInternalServerError) |
| 1492 | 1492 |
|
| ... | ... |
@@ -1501,7 +1492,7 @@ func (s *DockerSuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *che |
| 1501 | 1501 |
OomScoreAdj int |
| 1502 | 1502 |
}{"busybox", -1001}
|
| 1503 | 1503 |
name = "oomscoreadj-low" |
| 1504 |
- status, b, err = sockRequest("POST", "/containers/create?name="+name, config)
|
|
| 1504 |
+ status, b, err = request.SockRequest("POST", "/containers/create?name="+name, config, daemonHost())
|
|
| 1505 | 1505 |
c.Assert(err, check.IsNil) |
| 1506 | 1506 |
c.Assert(status, check.Equals, http.StatusInternalServerError) |
| 1507 | 1507 |
expected = "Invalid value -1001, range for oom score adj is [-1000, 1000]" |
| ... | ... |
@@ -1513,7 +1504,7 @@ func (s *DockerSuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *che |
| 1513 | 1513 |
|
| 1514 | 1514 |
// test case for #22210 where an empty container name caused panic. |
| 1515 | 1515 |
func (s *DockerSuite) TestContainerAPIDeleteWithEmptyName(c *check.C) {
|
| 1516 |
- status, out, err := sockRequest("DELETE", "/containers/", nil)
|
|
| 1516 |
+ status, out, err := request.SockRequest("DELETE", "/containers/", nil, daemonHost())
|
|
| 1517 | 1517 |
c.Assert(err, checker.IsNil) |
| 1518 | 1518 |
c.Assert(status, checker.Equals, http.StatusBadRequest) |
| 1519 | 1519 |
c.Assert(string(out), checker.Contains, "No container name or ID supplied") |
| ... | ... |
@@ -1530,11 +1521,11 @@ func (s *DockerSuite) TestContainerAPIStatsWithNetworkDisabled(c *check.C) {
|
| 1530 | 1530 |
"NetworkDisabled": true, |
| 1531 | 1531 |
} |
| 1532 | 1532 |
|
| 1533 |
- status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
|
|
| 1533 |
+ status, _, err := request.SockRequest("POST", "/containers/create?name="+name, config, daemonHost())
|
|
| 1534 | 1534 |
c.Assert(err, checker.IsNil) |
| 1535 | 1535 |
c.Assert(status, checker.Equals, http.StatusCreated) |
| 1536 | 1536 |
|
| 1537 |
- status, _, err = sockRequest("POST", "/containers/"+name+"/start", nil)
|
|
| 1537 |
+ status, _, err = request.SockRequest("POST", "/containers/"+name+"/start", nil, daemonHost())
|
|
| 1538 | 1538 |
c.Assert(err, checker.IsNil) |
| 1539 | 1539 |
c.Assert(status, checker.Equals, http.StatusNoContent) |
| 1540 | 1540 |
|
| ... | ... |
@@ -1547,7 +1538,7 @@ func (s *DockerSuite) TestContainerAPIStatsWithNetworkDisabled(c *check.C) {
|
| 1547 | 1547 |
} |
| 1548 | 1548 |
bc := make(chan b, 1) |
| 1549 | 1549 |
go func() {
|
| 1550 |
- status, body, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
|
|
| 1550 |
+ status, body, err := request.SockRequest("GET", "/containers/"+name+"/stats", nil, daemonHost())
|
|
| 1551 | 1551 |
bc <- b{status, body, err}
|
| 1552 | 1552 |
}() |
| 1553 | 1553 |
|
| ... | ... |
@@ -1755,7 +1746,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *check.C) {
|
| 1755 | 1755 |
|
| 1756 | 1756 |
for i, x := range cases {
|
| 1757 | 1757 |
c.Logf("case %d", i)
|
| 1758 |
- status, b, err := sockRequest("POST", "/containers/create", x.config)
|
|
| 1758 |
+ status, b, err := request.SockRequest("POST", "/containers/create", x.config, daemonHost())
|
|
| 1759 | 1759 |
c.Assert(err, checker.IsNil) |
| 1760 | 1760 |
c.Assert(status, checker.Equals, x.status, check.Commentf("%s\n%v", string(b), cases[i].config))
|
| 1761 | 1761 |
if len(x.msg) > 0 {
|
| ... | ... |
@@ -1780,7 +1771,7 @@ func (s *DockerSuite) TestContainerAPICreateMountsBindRead(c *check.C) {
|
| 1780 | 1780 |
"Cmd": []string{"/bin/sh", "-c", "cat /foo/bar"},
|
| 1781 | 1781 |
"HostConfig": map[string]interface{}{"Mounts": []map[string]interface{}{{"Type": "bind", "Source": tmpDir, "Target": destPath}}},
|
| 1782 | 1782 |
} |
| 1783 |
- status, resp, err := sockRequest("POST", "/containers/create?name=test", data)
|
|
| 1783 |
+ status, resp, err := request.SockRequest("POST", "/containers/create?name=test", data, daemonHost())
|
|
| 1784 | 1784 |
c.Assert(err, checker.IsNil, check.Commentf(string(resp))) |
| 1785 | 1785 |
c.Assert(status, checker.Equals, http.StatusCreated, check.Commentf(string(resp))) |
| 1786 | 1786 |
|
| ... | ... |
@@ -1868,7 +1859,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *check.C) {
|
| 1868 | 1868 |
} |
| 1869 | 1869 |
for i, x := range cases {
|
| 1870 | 1870 |
c.Logf("case %d - config: %v", i, x.cfg)
|
| 1871 |
- status, data, err := sockRequest("POST", "/containers/create", wrapper{containertypes.Config{Image: testImg}, containertypes.HostConfig{Mounts: []mounttypes.Mount{x.cfg}}})
|
|
| 1871 |
+ status, data, err := request.SockRequest("POST", "/containers/create", wrapper{containertypes.Config{Image: testImg}, containertypes.HostConfig{Mounts: []mounttypes.Mount{x.cfg}}}, daemonHost())
|
|
| 1872 | 1872 |
c.Assert(err, checker.IsNil, check.Commentf(string(data))) |
| 1873 | 1873 |
c.Assert(status, checker.Equals, http.StatusCreated, check.Commentf(string(data))) |
| 1874 | 1874 |
|
| ... | ... |
@@ -1950,7 +1941,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsTmpfs(c *check.C) {
|
| 1950 | 1950 |
fmt.Sprintf("mount | grep 'tmpfs on %s'", target)},
|
| 1951 | 1951 |
"HostConfig": map[string]interface{}{"Mounts": []map[string]interface{}{x.cfg}},
|
| 1952 | 1952 |
} |
| 1953 |
- status, resp, err := sockRequest("POST", "/containers/create?name="+cName, data)
|
|
| 1953 |
+ status, resp, err := request.SockRequest("POST", "/containers/create?name="+cName, data, daemonHost())
|
|
| 1954 | 1954 |
c.Assert(err, checker.IsNil, check.Commentf(string(resp))) |
| 1955 | 1955 |
c.Assert(status, checker.Equals, http.StatusCreated, check.Commentf(string(resp))) |
| 1956 | 1956 |
out, _ := dockerCmd(c, "start", "-a", cName) |
| ... | ... |
@@ -4,6 +4,7 @@ import ( |
| 4 | 4 |
"net/http" |
| 5 | 5 |
|
| 6 | 6 |
"github.com/docker/docker/integration-cli/checker" |
| 7 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 7 | 8 |
"github.com/go-check/check" |
| 8 | 9 |
) |
| 9 | 10 |
|
| ... | ... |
@@ -14,7 +15,7 @@ func (s *DockerSuite) TestAPICreateWithNotExistImage(c *check.C) {
|
| 14 | 14 |
"Volumes": map[string]struct{}{"/tmp": {}},
|
| 15 | 15 |
} |
| 16 | 16 |
|
| 17 |
- status, body, err := sockRequest("POST", "/containers/create?name="+name, config)
|
|
| 17 |
+ status, body, err := request.SockRequest("POST", "/containers/create?name="+name, config, daemonHost())
|
|
| 18 | 18 |
c.Assert(err, check.IsNil) |
| 19 | 19 |
c.Assert(status, check.Equals, http.StatusNotFound) |
| 20 | 20 |
expected := "No such image: test456:v1" |
| ... | ... |
@@ -25,7 +26,7 @@ func (s *DockerSuite) TestAPICreateWithNotExistImage(c *check.C) {
|
| 25 | 25 |
"Volumes": map[string]struct{}{"/tmp": {}},
|
| 26 | 26 |
} |
| 27 | 27 |
|
| 28 |
- status, body, err = sockRequest("POST", "/containers/create?name="+name, config2)
|
|
| 28 |
+ status, body, err = request.SockRequest("POST", "/containers/create?name="+name, config2, daemonHost())
|
|
| 29 | 29 |
c.Assert(err, check.IsNil) |
| 30 | 30 |
c.Assert(status, check.Equals, http.StatusNotFound) |
| 31 | 31 |
expected = "No such image: test456:latest" |
| ... | ... |
@@ -35,7 +36,7 @@ func (s *DockerSuite) TestAPICreateWithNotExistImage(c *check.C) {
|
| 35 | 35 |
"Image": "sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa", |
| 36 | 36 |
} |
| 37 | 37 |
|
| 38 |
- status, body, err = sockRequest("POST", "/containers/create?name="+name, config3)
|
|
| 38 |
+ status, body, err = request.SockRequest("POST", "/containers/create?name="+name, config3, daemonHost())
|
|
| 39 | 39 |
c.Assert(err, check.IsNil) |
| 40 | 40 |
c.Assert(status, check.Equals, http.StatusNotFound) |
| 41 | 41 |
expected = "No such image: sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efeaaaa" |
| ... | ... |
@@ -52,7 +53,7 @@ func (s *DockerSuite) TestAPICreateEmptyEnv(c *check.C) {
|
| 52 | 52 |
"Cmd": []string{"true"},
|
| 53 | 53 |
} |
| 54 | 54 |
|
| 55 |
- status, body, err := sockRequest("POST", "/containers/create?name="+name, config)
|
|
| 55 |
+ status, body, err := request.SockRequest("POST", "/containers/create?name="+name, config, daemonHost())
|
|
| 56 | 56 |
c.Assert(err, check.IsNil) |
| 57 | 57 |
c.Assert(status, check.Equals, http.StatusInternalServerError) |
| 58 | 58 |
expected := "invalid environment variable:" |
| ... | ... |
@@ -64,7 +65,7 @@ func (s *DockerSuite) TestAPICreateEmptyEnv(c *check.C) {
|
| 64 | 64 |
"Env": []string{"=", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"},
|
| 65 | 65 |
"Cmd": []string{"true"},
|
| 66 | 66 |
} |
| 67 |
- status, body, err = sockRequest("POST", "/containers/create?name="+name, config)
|
|
| 67 |
+ status, body, err = request.SockRequest("POST", "/containers/create?name="+name, config, daemonHost())
|
|
| 68 | 68 |
c.Assert(err, check.IsNil) |
| 69 | 69 |
c.Assert(status, check.Equals, http.StatusInternalServerError) |
| 70 | 70 |
expected = "invalid environment variable: =" |
| ... | ... |
@@ -76,7 +77,7 @@ func (s *DockerSuite) TestAPICreateEmptyEnv(c *check.C) {
|
| 76 | 76 |
"Env": []string{"=foo", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"},
|
| 77 | 77 |
"Cmd": []string{"true"},
|
| 78 | 78 |
} |
| 79 |
- status, body, err = sockRequest("POST", "/containers/create?name="+name, config)
|
|
| 79 |
+ status, body, err = request.SockRequest("POST", "/containers/create?name="+name, config, daemonHost())
|
|
| 80 | 80 |
c.Assert(err, check.IsNil) |
| 81 | 81 |
c.Assert(status, check.Equals, http.StatusInternalServerError) |
| 82 | 82 |
expected = "invalid environment variable: =foo" |
| ... | ... |
@@ -10,6 +10,7 @@ import ( |
| 10 | 10 |
"time" |
| 11 | 11 |
|
| 12 | 12 |
"github.com/docker/docker/integration-cli/checker" |
| 13 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 13 | 14 |
"github.com/docker/docker/pkg/jsonmessage" |
| 14 | 15 |
"github.com/go-check/check" |
| 15 | 16 |
) |
| ... | ... |
@@ -21,7 +22,7 @@ func (s *DockerSuite) TestEventsAPIEmptyOutput(c *check.C) {
|
| 21 | 21 |
} |
| 22 | 22 |
chResp := make(chan *apiResp) |
| 23 | 23 |
go func() {
|
| 24 |
- resp, body, err := sockRequestRaw("GET", "/events", nil, "")
|
|
| 24 |
+ resp, body, err := request.SockRequestRaw("GET", "/events", nil, "", daemonHost())
|
|
| 25 | 25 |
body.Close() |
| 26 | 26 |
chResp <- &apiResp{resp, err}
|
| 27 | 27 |
}() |
| ... | ... |
@@ -46,7 +47,7 @@ func (s *DockerSuite) TestEventsAPIBackwardsCompatible(c *check.C) {
|
| 46 | 46 |
q := url.Values{}
|
| 47 | 47 |
q.Set("since", ts)
|
| 48 | 48 |
|
| 49 |
- _, body, err := sockRequestRaw("GET", "/events?"+q.Encode(), nil, "")
|
|
| 49 |
+ _, body, err := request.SockRequestRaw("GET", "/events?"+q.Encode(), nil, "", daemonHost())
|
|
| 50 | 50 |
c.Assert(err, checker.IsNil) |
| 51 | 51 |
defer body.Close() |
| 52 | 52 |
|
| ... | ... |
@@ -10,6 +10,7 @@ import ( |
| 10 | 10 |
"sync" |
| 11 | 11 |
|
| 12 | 12 |
"github.com/docker/docker/integration-cli/checker" |
| 13 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 13 | 14 |
"github.com/go-check/check" |
| 14 | 15 |
) |
| 15 | 16 |
|
| ... | ... |
@@ -19,7 +20,7 @@ func (s *DockerSuite) TestExecResizeAPIHeightWidthNoInt(c *check.C) {
|
| 19 | 19 |
cleanedContainerID := strings.TrimSpace(out) |
| 20 | 20 |
|
| 21 | 21 |
endpoint := "/exec/" + cleanedContainerID + "/resize?h=foo&w=bar" |
| 22 |
- status, _, err := sockRequest("POST", endpoint, nil)
|
|
| 22 |
+ status, _, err := request.SockRequest("POST", endpoint, nil, daemonHost())
|
|
| 23 | 23 |
c.Assert(err, checker.IsNil) |
| 24 | 24 |
c.Assert(status, checker.Equals, http.StatusInternalServerError) |
| 25 | 25 |
} |
| ... | ... |
@@ -35,7 +36,7 @@ func (s *DockerSuite) TestExecResizeImmediatelyAfterExecStart(c *check.C) {
|
| 35 | 35 |
"Cmd": []string{"/bin/sh"},
|
| 36 | 36 |
} |
| 37 | 37 |
uri := fmt.Sprintf("/containers/%s/exec", name)
|
| 38 |
- status, body, err := sockRequest("POST", uri, data)
|
|
| 38 |
+ status, body, err := request.SockRequest("POST", uri, data, daemonHost())
|
|
| 39 | 39 |
if err != nil {
|
| 40 | 40 |
return err |
| 41 | 41 |
} |
| ... | ... |
@@ -55,13 +56,13 @@ func (s *DockerSuite) TestExecResizeImmediatelyAfterExecStart(c *check.C) {
|
| 55 | 55 |
} |
| 56 | 56 |
|
| 57 | 57 |
payload := bytes.NewBufferString(`{"Tty":true}`)
|
| 58 |
- conn, _, err := sockRequestHijack("POST", fmt.Sprintf("/exec/%s/start", execID), payload, "application/json")
|
|
| 58 |
+ conn, _, err := request.SockRequestHijack("POST", fmt.Sprintf("/exec/%s/start", execID), payload, "application/json", daemonHost())
|
|
| 59 | 59 |
if err != nil {
|
| 60 | 60 |
return fmt.Errorf("Failed to start the exec: %q", err.Error())
|
| 61 | 61 |
} |
| 62 | 62 |
defer conn.Close() |
| 63 | 63 |
|
| 64 |
- _, rc, err := sockRequestRaw("POST", fmt.Sprintf("/exec/%s/resize?h=24&w=80", execID), nil, "text/plain")
|
|
| 64 |
+ _, rc, err := request.SockRequestRaw("POST", fmt.Sprintf("/exec/%s/resize?h=24&w=80", execID), nil, "text/plain", daemonHost())
|
|
| 65 | 65 |
// It's probably a panic of the daemon if io.ErrUnexpectedEOF is returned. |
| 66 | 66 |
if err == io.ErrUnexpectedEOF {
|
| 67 | 67 |
return fmt.Errorf("The daemon might have crashed.")
|
| ... | ... |
@@ -11,6 +11,7 @@ import ( |
| 11 | 11 |
"time" |
| 12 | 12 |
|
| 13 | 13 |
"github.com/docker/docker/integration-cli/checker" |
| 14 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 14 | 15 |
"github.com/docker/docker/pkg/testutil" |
| 15 | 16 |
"github.com/go-check/check" |
| 16 | 17 |
) |
| ... | ... |
@@ -20,7 +21,7 @@ func (s *DockerSuite) TestExecAPICreateNoCmd(c *check.C) {
|
| 20 | 20 |
name := "exec_test" |
| 21 | 21 |
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") |
| 22 | 22 |
|
| 23 |
- status, body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": nil})
|
|
| 23 |
+ status, body, err := request.SockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": nil}, daemonHost())
|
|
| 24 | 24 |
c.Assert(err, checker.IsNil) |
| 25 | 25 |
c.Assert(status, checker.Equals, http.StatusInternalServerError) |
| 26 | 26 |
|
| ... | ... |
@@ -37,7 +38,7 @@ func (s *DockerSuite) TestExecAPICreateNoValidContentType(c *check.C) {
|
| 37 | 37 |
c.Fatalf("Can not encode data to json %s", err)
|
| 38 | 38 |
} |
| 39 | 39 |
|
| 40 |
- res, body, err := sockRequestRaw("POST", fmt.Sprintf("/containers/%s/exec", name), jsonData, "text/plain")
|
|
| 40 |
+ res, body, err := request.SockRequestRaw("POST", fmt.Sprintf("/containers/%s/exec", name), jsonData, "text/plain", daemonHost())
|
|
| 41 | 41 |
c.Assert(err, checker.IsNil) |
| 42 | 42 |
c.Assert(res.StatusCode, checker.Equals, http.StatusInternalServerError) |
| 43 | 43 |
|
| ... | ... |
@@ -55,7 +56,7 @@ func (s *DockerSuite) TestExecAPICreateContainerPaused(c *check.C) {
|
| 55 | 55 |
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") |
| 56 | 56 |
|
| 57 | 57 |
dockerCmd(c, "pause", name) |
| 58 |
- status, body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": []string{"true"}})
|
|
| 58 |
+ status, body, err := request.SockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": []string{"true"}}, daemonHost())
|
|
| 59 | 59 |
c.Assert(err, checker.IsNil) |
| 60 | 60 |
c.Assert(status, checker.Equals, http.StatusConflict) |
| 61 | 61 |
|
| ... | ... |
@@ -95,7 +96,7 @@ func (s *DockerSuite) TestExecAPIStartEnsureHeaders(c *check.C) {
|
| 95 | 95 |
dockerCmd(c, "run", "-d", "--name", "test", "busybox", "top") |
| 96 | 96 |
|
| 97 | 97 |
id := createExec(c, "test") |
| 98 |
- resp, _, err := sockRequestRaw("POST", fmt.Sprintf("/exec/%s/start", id), strings.NewReader(`{"Detach": true}`), "application/json")
|
|
| 98 |
+ resp, _, err := request.SockRequestRaw("POST", fmt.Sprintf("/exec/%s/start", id), strings.NewReader(`{"Detach": true}`), "application/json", daemonHost())
|
|
| 99 | 99 |
c.Assert(err, checker.IsNil) |
| 100 | 100 |
c.Assert(resp.Header.Get("Server"), checker.Not(checker.Equals), "")
|
| 101 | 101 |
} |
| ... | ... |
@@ -105,7 +106,7 @@ func (s *DockerSuite) TestExecAPIStartBackwardsCompatible(c *check.C) {
|
| 105 | 105 |
runSleepingContainer(c, "-d", "--name", "test") |
| 106 | 106 |
id := createExec(c, "test") |
| 107 | 107 |
|
| 108 |
- resp, body, err := sockRequestRaw("POST", fmt.Sprintf("/v1.20/exec/%s/start", id), strings.NewReader(`{"Detach": true}`), "text/plain")
|
|
| 108 |
+ resp, body, err := request.SockRequestRaw("POST", fmt.Sprintf("/v1.20/exec/%s/start", id), strings.NewReader(`{"Detach": true}`), "text/plain", daemonHost())
|
|
| 109 | 109 |
c.Assert(err, checker.IsNil) |
| 110 | 110 |
|
| 111 | 111 |
b, err := testutil.ReadBody(body) |
| ... | ... |
@@ -146,7 +147,7 @@ func (s *DockerSuite) TestExecAPIStartWithDetach(c *check.C) {
|
| 146 | 146 |
"cmd": []string{"true"},
|
| 147 | 147 |
"AttachStdin": true, |
| 148 | 148 |
} |
| 149 |
- _, b, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), data)
|
|
| 149 |
+ _, b, err := request.SockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), data, daemonHost())
|
|
| 150 | 150 |
c.Assert(err, checker.IsNil, check.Commentf(string(b))) |
| 151 | 151 |
|
| 152 | 152 |
createResp := struct {
|
| ... | ... |
@@ -154,14 +155,14 @@ func (s *DockerSuite) TestExecAPIStartWithDetach(c *check.C) {
|
| 154 | 154 |
}{}
|
| 155 | 155 |
c.Assert(json.Unmarshal(b, &createResp), checker.IsNil, check.Commentf(string(b))) |
| 156 | 156 |
|
| 157 |
- _, body, err := sockRequestRaw("POST", fmt.Sprintf("/exec/%s/start", createResp.ID), strings.NewReader(`{"Detach": true}`), "application/json")
|
|
| 157 |
+ _, body, err := request.SockRequestRaw("POST", fmt.Sprintf("/exec/%s/start", createResp.ID), strings.NewReader(`{"Detach": true}`), "application/json", daemonHost())
|
|
| 158 | 158 |
c.Assert(err, checker.IsNil) |
| 159 | 159 |
|
| 160 | 160 |
b, err = testutil.ReadBody(body) |
| 161 | 161 |
comment := check.Commentf("response body: %s", b)
|
| 162 | 162 |
c.Assert(err, checker.IsNil, comment) |
| 163 | 163 |
|
| 164 |
- resp, _, err := sockRequestRaw("GET", "/_ping", nil, "")
|
|
| 164 |
+ resp, _, err := request.SockRequestRaw("GET", "/_ping", nil, "", daemonHost())
|
|
| 165 | 165 |
c.Assert(err, checker.IsNil) |
| 166 | 166 |
if resp.StatusCode != http.StatusOK {
|
| 167 | 167 |
c.Fatal("daemon is down, it should alive")
|
| ... | ... |
@@ -169,7 +170,7 @@ func (s *DockerSuite) TestExecAPIStartWithDetach(c *check.C) {
|
| 169 | 169 |
} |
| 170 | 170 |
|
| 171 | 171 |
func createExec(c *check.C, name string) string {
|
| 172 |
- _, b, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": []string{"true"}})
|
|
| 172 |
+ _, b, err := request.SockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": []string{"true"}}, daemonHost())
|
|
| 173 | 173 |
c.Assert(err, checker.IsNil, check.Commentf(string(b))) |
| 174 | 174 |
|
| 175 | 175 |
createResp := struct {
|
| ... | ... |
@@ -180,7 +181,7 @@ func createExec(c *check.C, name string) string {
|
| 180 | 180 |
} |
| 181 | 181 |
|
| 182 | 182 |
func startExec(c *check.C, id string, code int) {
|
| 183 |
- resp, body, err := sockRequestRaw("POST", fmt.Sprintf("/exec/%s/start", id), strings.NewReader(`{"Detach": true}`), "application/json")
|
|
| 183 |
+ resp, body, err := request.SockRequestRaw("POST", fmt.Sprintf("/exec/%s/start", id), strings.NewReader(`{"Detach": true}`), "application/json", daemonHost())
|
|
| 184 | 184 |
c.Assert(err, checker.IsNil) |
| 185 | 185 |
|
| 186 | 186 |
b, err := testutil.ReadBody(body) |
| ... | ... |
@@ -190,7 +191,7 @@ func startExec(c *check.C, id string, code int) {
|
| 190 | 190 |
} |
| 191 | 191 |
|
| 192 | 192 |
func inspectExec(c *check.C, id string, out interface{}) {
|
| 193 |
- resp, body, err := sockRequestRaw("GET", fmt.Sprintf("/exec/%s/json", id), nil, "")
|
|
| 193 |
+ resp, body, err := request.SockRequestRaw("GET", fmt.Sprintf("/exec/%s/json", id), nil, "", daemonHost())
|
|
| 194 | 194 |
c.Assert(err, checker.IsNil) |
| 195 | 195 |
defer body.Close() |
| 196 | 196 |
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK) |
| ... | ... |
@@ -8,6 +8,7 @@ import ( |
| 8 | 8 |
|
| 9 | 9 |
"github.com/docker/docker/api/types" |
| 10 | 10 |
"github.com/docker/docker/integration-cli/checker" |
| 11 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 11 | 12 |
"github.com/go-check/check" |
| 12 | 13 |
) |
| 13 | 14 |
|
| ... | ... |
@@ -22,7 +23,7 @@ func (s *DockerSuite) TestAPIImagesFilter(c *check.C) {
|
| 22 | 22 |
getImages := func(filter string) []image {
|
| 23 | 23 |
v := url.Values{}
|
| 24 | 24 |
v.Set("filter", filter)
|
| 25 |
- status, b, err := sockRequest("GET", "/images/json?"+v.Encode(), nil)
|
|
| 25 |
+ status, b, err := request.SockRequest("GET", "/images/json?"+v.Encode(), nil, daemonHost())
|
|
| 26 | 26 |
c.Assert(err, checker.IsNil) |
| 27 | 27 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 28 | 28 |
|
| ... | ... |
@@ -55,14 +56,14 @@ func (s *DockerSuite) TestAPIImagesSaveAndLoad(c *check.C) {
|
| 55 | 55 |
c.Assert(err, checker.IsNil) |
| 56 | 56 |
id := strings.TrimSpace(out) |
| 57 | 57 |
|
| 58 |
- res, body, err := sockRequestRaw("GET", "/images/"+id+"/get", nil, "")
|
|
| 58 |
+ res, body, err := request.SockRequestRaw("GET", "/images/"+id+"/get", nil, "", daemonHost())
|
|
| 59 | 59 |
c.Assert(err, checker.IsNil) |
| 60 | 60 |
defer body.Close() |
| 61 | 61 |
c.Assert(res.StatusCode, checker.Equals, http.StatusOK) |
| 62 | 62 |
|
| 63 | 63 |
dockerCmd(c, "rmi", id) |
| 64 | 64 |
|
| 65 |
- res, loadBody, err := sockRequestRaw("POST", "/images/load", body, "application/x-tar")
|
|
| 65 |
+ res, loadBody, err := request.SockRequestRaw("POST", "/images/load", body, "application/x-tar", daemonHost())
|
|
| 66 | 66 |
c.Assert(err, checker.IsNil) |
| 67 | 67 |
defer loadBody.Close() |
| 68 | 68 |
c.Assert(res.StatusCode, checker.Equals, http.StatusOK) |
| ... | ... |
@@ -82,15 +83,15 @@ func (s *DockerSuite) TestAPIImagesDelete(c *check.C) {
|
| 82 | 82 |
|
| 83 | 83 |
dockerCmd(c, "tag", name, "test:tag1") |
| 84 | 84 |
|
| 85 |
- status, _, err := sockRequest("DELETE", "/images/"+id, nil)
|
|
| 85 |
+ status, _, err := request.SockRequest("DELETE", "/images/"+id, nil, daemonHost())
|
|
| 86 | 86 |
c.Assert(err, checker.IsNil) |
| 87 | 87 |
c.Assert(status, checker.Equals, http.StatusConflict) |
| 88 | 88 |
|
| 89 |
- status, _, err = sockRequest("DELETE", "/images/test:noexist", nil)
|
|
| 89 |
+ status, _, err = request.SockRequest("DELETE", "/images/test:noexist", nil, daemonHost())
|
|
| 90 | 90 |
c.Assert(err, checker.IsNil) |
| 91 | 91 |
c.Assert(status, checker.Equals, http.StatusNotFound) //Status Codes:404 – no such image |
| 92 | 92 |
|
| 93 |
- status, _, err = sockRequest("DELETE", "/images/test:tag1", nil)
|
|
| 93 |
+ status, _, err = request.SockRequest("DELETE", "/images/test:tag1", nil, daemonHost())
|
|
| 94 | 94 |
c.Assert(err, checker.IsNil) |
| 95 | 95 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 96 | 96 |
} |
| ... | ... |
@@ -105,7 +106,7 @@ func (s *DockerSuite) TestAPIImagesHistory(c *check.C) {
|
| 105 | 105 |
|
| 106 | 106 |
id := strings.TrimSpace(out) |
| 107 | 107 |
|
| 108 |
- status, body, err := sockRequest("GET", "/images/"+id+"/history", nil)
|
|
| 108 |
+ status, body, err := request.SockRequest("GET", "/images/"+id+"/history", nil, daemonHost())
|
|
| 109 | 109 |
c.Assert(err, checker.IsNil) |
| 110 | 110 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 111 | 111 |
|
| ... | ... |
@@ -121,7 +122,7 @@ func (s *DockerSuite) TestAPIImagesHistory(c *check.C) {
|
| 121 | 121 |
func (s *DockerSuite) TestAPIImagesSearchJSONContentType(c *check.C) {
|
| 122 | 122 |
testRequires(c, Network) |
| 123 | 123 |
|
| 124 |
- res, b, err := sockRequestRaw("GET", "/images/search?term=test", nil, "application/json")
|
|
| 124 |
+ res, b, err := request.SockRequestRaw("GET", "/images/search?term=test", nil, "application/json", daemonHost())
|
|
| 125 | 125 |
c.Assert(err, check.IsNil) |
| 126 | 126 |
b.Close() |
| 127 | 127 |
c.Assert(res.StatusCode, checker.Equals, http.StatusOK) |
| ... | ... |
@@ -4,13 +4,14 @@ import ( |
| 4 | 4 |
"net/http" |
| 5 | 5 |
|
| 6 | 6 |
"github.com/docker/docker/integration-cli/checker" |
| 7 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 7 | 8 |
"github.com/go-check/check" |
| 8 | 9 |
) |
| 9 | 10 |
|
| 10 | 11 |
func (s *DockerSuite) TestInfoAPI(c *check.C) {
|
| 11 | 12 |
endpoint := "/info" |
| 12 | 13 |
|
| 13 |
- status, body, err := sockRequest("GET", endpoint, nil)
|
|
| 14 |
+ status, body, err := request.SockRequest("GET", endpoint, nil, daemonHost())
|
|
| 14 | 15 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 15 | 16 |
c.Assert(err, checker.IsNil) |
| 16 | 17 |
|
| ... | ... |
@@ -43,7 +44,7 @@ func (s *DockerSuite) TestInfoAPIVersioned(c *check.C) {
|
| 43 | 43 |
testRequires(c, DaemonIsLinux) // Windows only supports 1.25 or later |
| 44 | 44 |
endpoint := "/v1.20/info" |
| 45 | 45 |
|
| 46 |
- status, body, err := sockRequest("GET", endpoint, nil)
|
|
| 46 |
+ status, body, err := request.SockRequest("GET", endpoint, nil, daemonHost())
|
|
| 47 | 47 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 48 | 48 |
c.Assert(err, checker.IsNil) |
| 49 | 49 |
|
| ... | ... |
@@ -8,6 +8,7 @@ import ( |
| 8 | 8 |
"github.com/docker/docker/api/types" |
| 9 | 9 |
"github.com/docker/docker/api/types/versions/v1p20" |
| 10 | 10 |
"github.com/docker/docker/integration-cli/checker" |
| 11 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 11 | 12 |
"github.com/docker/docker/pkg/stringutils" |
| 12 | 13 |
"github.com/go-check/check" |
| 13 | 14 |
) |
| ... | ... |
@@ -107,7 +108,7 @@ func (s *DockerSuite) TestInspectAPIImageResponse(c *check.C) {
|
| 107 | 107 |
dockerCmd(c, "tag", "busybox:latest", "busybox:mytag") |
| 108 | 108 |
|
| 109 | 109 |
endpoint := "/images/busybox/json" |
| 110 |
- status, body, err := sockRequest("GET", endpoint, nil)
|
|
| 110 |
+ status, body, err := request.SockRequest("GET", endpoint, nil, daemonHost())
|
|
| 111 | 111 |
|
| 112 | 112 |
c.Assert(err, checker.IsNil) |
| 113 | 113 |
c.Assert(status, checker.Equals, http.StatusOK) |
| ... | ... |
@@ -8,6 +8,7 @@ import ( |
| 8 | 8 |
"net/http" |
| 9 | 9 |
|
| 10 | 10 |
"github.com/docker/docker/integration-cli/checker" |
| 11 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 11 | 12 |
"github.com/go-check/check" |
| 12 | 13 |
) |
| 13 | 14 |
|
| ... | ... |
@@ -19,7 +20,7 @@ func (s *DockerSuite) TestInspectAPICpusetInConfigPre120(c *check.C) {
|
| 19 | 19 |
name := "cpusetinconfig-pre120" |
| 20 | 20 |
dockerCmd(c, "run", "--name", name, "--cpuset-cpus", "0", "busybox", "true") |
| 21 | 21 |
|
| 22 |
- status, body, err := sockRequest("GET", fmt.Sprintf("/v1.19/containers/%s/json", name), nil)
|
|
| 22 |
+ status, body, err := request.SockRequest("GET", fmt.Sprintf("/v1.19/containers/%s/json", name), nil, daemonHost())
|
|
| 23 | 23 |
c.Assert(status, check.Equals, http.StatusOK) |
| 24 | 24 |
c.Assert(err, check.IsNil) |
| 25 | 25 |
|
| ... | ... |
@@ -9,6 +9,7 @@ import ( |
| 9 | 9 |
"time" |
| 10 | 10 |
|
| 11 | 11 |
"github.com/docker/docker/integration-cli/checker" |
| 12 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 12 | 13 |
"github.com/go-check/check" |
| 13 | 14 |
) |
| 14 | 15 |
|
| ... | ... |
@@ -25,7 +26,7 @@ func (s *DockerSuite) TestLogsAPIWithStdout(c *check.C) {
|
| 25 | 25 |
chLog := make(chan logOut) |
| 26 | 26 |
|
| 27 | 27 |
go func() {
|
| 28 |
- res, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1×tamps=1", id), nil, "")
|
|
| 28 |
+ res, body, err := request.SockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1×tamps=1", id), nil, "", daemonHost())
|
|
| 29 | 29 |
if err != nil {
|
| 30 | 30 |
chLog <- logOut{"", nil, err}
|
| 31 | 31 |
return |
| ... | ... |
@@ -55,7 +56,7 @@ func (s *DockerSuite) TestLogsAPINoStdoutNorStderr(c *check.C) {
|
| 55 | 55 |
name := "logs_test" |
| 56 | 56 |
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") |
| 57 | 57 |
|
| 58 |
- status, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs", name), nil)
|
|
| 58 |
+ status, body, err := request.SockRequest("GET", fmt.Sprintf("/containers/%s/logs", name), nil, daemonHost())
|
|
| 59 | 59 |
c.Assert(status, checker.Equals, http.StatusBadRequest) |
| 60 | 60 |
c.Assert(err, checker.IsNil) |
| 61 | 61 |
|
| ... | ... |
@@ -69,7 +70,7 @@ func (s *DockerSuite) TestLogsAPIFollowEmptyOutput(c *check.C) {
|
| 69 | 69 |
t0 := time.Now() |
| 70 | 70 |
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "sleep", "10") |
| 71 | 71 |
|
| 72 |
- _, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name), bytes.NewBuffer(nil), "")
|
|
| 72 |
+ _, body, err := request.SockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name), bytes.NewBuffer(nil), "", daemonHost())
|
|
| 73 | 73 |
t1 := time.Now() |
| 74 | 74 |
c.Assert(err, checker.IsNil) |
| 75 | 75 |
body.Close() |
| ... | ... |
@@ -81,7 +82,7 @@ func (s *DockerSuite) TestLogsAPIFollowEmptyOutput(c *check.C) {
|
| 81 | 81 |
|
| 82 | 82 |
func (s *DockerSuite) TestLogsAPIContainerNotFound(c *check.C) {
|
| 83 | 83 |
name := "nonExistentContainer" |
| 84 |
- resp, _, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name), bytes.NewBuffer(nil), "")
|
|
| 84 |
+ resp, _, err := request.SockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name), bytes.NewBuffer(nil), "", daemonHost())
|
|
| 85 | 85 |
c.Assert(err, checker.IsNil) |
| 86 | 86 |
c.Assert(resp.StatusCode, checker.Equals, http.StatusNotFound) |
| 87 | 87 |
} |
| ... | ... |
@@ -12,6 +12,7 @@ import ( |
| 12 | 12 |
"github.com/docker/docker/api/types/filters" |
| 13 | 13 |
"github.com/docker/docker/api/types/network" |
| 14 | 14 |
"github.com/docker/docker/integration-cli/checker" |
| 15 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 15 | 16 |
"github.com/go-check/check" |
| 16 | 17 |
) |
| 17 | 18 |
|
| ... | ... |
@@ -256,12 +257,12 @@ func createDeletePredefinedNetwork(c *check.C, name string) {
|
| 256 | 256 |
} |
| 257 | 257 |
|
| 258 | 258 |
func isNetworkAvailable(c *check.C, name string) bool {
|
| 259 |
- status, body, err := sockRequest("GET", "/networks", nil)
|
|
| 260 |
- c.Assert(status, checker.Equals, http.StatusOK) |
|
| 259 |
+ resp, body, err := request.Get(daemonHost(), "/networks") |
|
| 260 |
+ c.Assert(resp.StatusCode, checker.Equals, http.StatusOK) |
|
| 261 | 261 |
c.Assert(err, checker.IsNil) |
| 262 | 262 |
|
| 263 | 263 |
nJSON := []types.NetworkResource{}
|
| 264 |
- err = json.Unmarshal(body, &nJSON) |
|
| 264 |
+ err = json.NewDecoder(body).Decode(&nJSON) |
|
| 265 | 265 |
c.Assert(err, checker.IsNil) |
| 266 | 266 |
|
| 267 | 267 |
for _, n := range nJSON {
|
| ... | ... |
@@ -282,12 +283,12 @@ func getNetworkIDByName(c *check.C, name string) string {
|
| 282 | 282 |
c.Assert(err, checker.IsNil) |
| 283 | 283 |
v.Set("filters", filterJSON)
|
| 284 | 284 |
|
| 285 |
- status, body, err := sockRequest("GET", "/networks?"+v.Encode(), nil)
|
|
| 286 |
- c.Assert(status, checker.Equals, http.StatusOK) |
|
| 285 |
+ resp, body, err := request.Get(daemonHost(), "/networks?"+v.Encode()) |
|
| 286 |
+ c.Assert(resp.StatusCode, checker.Equals, http.StatusOK) |
|
| 287 | 287 |
c.Assert(err, checker.IsNil) |
| 288 | 288 |
|
| 289 | 289 |
nJSON := []types.NetworkResource{}
|
| 290 |
- err = json.Unmarshal(body, &nJSON) |
|
| 290 |
+ err = json.NewDecoder(body).Decode(&nJSON) |
|
| 291 | 291 |
c.Assert(err, checker.IsNil) |
| 292 | 292 |
c.Assert(len(nJSON), checker.Equals, 1) |
| 293 | 293 |
|
| ... | ... |
@@ -295,28 +296,28 @@ func getNetworkIDByName(c *check.C, name string) string {
|
| 295 | 295 |
} |
| 296 | 296 |
|
| 297 | 297 |
func getNetworkResource(c *check.C, id string) *types.NetworkResource {
|
| 298 |
- _, obj, err := sockRequest("GET", "/networks/"+id, nil)
|
|
| 298 |
+ _, obj, err := request.Get(daemonHost(), "/networks/"+id) |
|
| 299 | 299 |
c.Assert(err, checker.IsNil) |
| 300 | 300 |
|
| 301 | 301 |
nr := types.NetworkResource{}
|
| 302 |
- err = json.Unmarshal(obj, &nr) |
|
| 302 |
+ err = json.NewDecoder(obj).Decode(&nr) |
|
| 303 | 303 |
c.Assert(err, checker.IsNil) |
| 304 | 304 |
|
| 305 | 305 |
return &nr |
| 306 | 306 |
} |
| 307 | 307 |
|
| 308 | 308 |
func createNetwork(c *check.C, config types.NetworkCreateRequest, shouldSucceed bool) string {
|
| 309 |
- status, resp, err := sockRequest("POST", "/networks/create", config)
|
|
| 309 |
+ resp, body, err := request.Post(daemonHost(), "/networks/create", request.JSONBody(config)) |
|
| 310 | 310 |
if !shouldSucceed {
|
| 311 |
- c.Assert(status, checker.Not(checker.Equals), http.StatusCreated) |
|
| 311 |
+ c.Assert(resp.StatusCode, checker.Not(checker.Equals), http.StatusCreated) |
|
| 312 | 312 |
return "" |
| 313 | 313 |
} |
| 314 | 314 |
|
| 315 | 315 |
c.Assert(err, checker.IsNil) |
| 316 |
- c.Assert(status, checker.Equals, http.StatusCreated) |
|
| 316 |
+ c.Assert(resp.StatusCode, checker.Equals, http.StatusCreated) |
|
| 317 | 317 |
|
| 318 | 318 |
var nr types.NetworkCreateResponse |
| 319 |
- err = json.Unmarshal(resp, &nr) |
|
| 319 |
+ err = json.NewDecoder(body).Decode(&nr) |
|
| 320 | 320 |
c.Assert(err, checker.IsNil) |
| 321 | 321 |
|
| 322 | 322 |
return nr.ID |
| ... | ... |
@@ -327,8 +328,8 @@ func connectNetwork(c *check.C, nid, cid string) {
|
| 327 | 327 |
Container: cid, |
| 328 | 328 |
} |
| 329 | 329 |
|
| 330 |
- status, _, err := sockRequest("POST", "/networks/"+nid+"/connect", config)
|
|
| 331 |
- c.Assert(status, checker.Equals, http.StatusOK) |
|
| 330 |
+ resp, _, err := request.Post(daemonHost(), "/networks/"+nid+"/connect", request.JSONBody(config)) |
|
| 331 |
+ c.Assert(resp.StatusCode, checker.Equals, http.StatusOK) |
|
| 332 | 332 |
c.Assert(err, checker.IsNil) |
| 333 | 333 |
} |
| 334 | 334 |
|
| ... | ... |
@@ -337,17 +338,17 @@ func disconnectNetwork(c *check.C, nid, cid string) {
|
| 337 | 337 |
Container: cid, |
| 338 | 338 |
} |
| 339 | 339 |
|
| 340 |
- status, _, err := sockRequest("POST", "/networks/"+nid+"/disconnect", config)
|
|
| 341 |
- c.Assert(status, checker.Equals, http.StatusOK) |
|
| 340 |
+ resp, _, err := request.Post(daemonHost(), "/networks/"+nid+"/disconnect", request.JSONBody(config)) |
|
| 341 |
+ c.Assert(resp.StatusCode, checker.Equals, http.StatusOK) |
|
| 342 | 342 |
c.Assert(err, checker.IsNil) |
| 343 | 343 |
} |
| 344 | 344 |
|
| 345 | 345 |
func deleteNetwork(c *check.C, id string, shouldSucceed bool) {
|
| 346 |
- status, _, err := sockRequest("DELETE", "/networks/"+id, nil)
|
|
| 346 |
+ resp, _, err := request.Delete(daemonHost(), "/networks/"+id) |
|
| 347 | 347 |
if !shouldSucceed {
|
| 348 |
- c.Assert(status, checker.Not(checker.Equals), http.StatusOK) |
|
| 348 |
+ c.Assert(resp.StatusCode, checker.Not(checker.Equals), http.StatusOK) |
|
| 349 | 349 |
return |
| 350 | 350 |
} |
| 351 |
- c.Assert(status, checker.Equals, http.StatusNoContent) |
|
| 351 |
+ c.Assert(resp.StatusCode, checker.Equals, http.StatusNoContent) |
|
| 352 | 352 |
c.Assert(err, checker.IsNil) |
| 353 | 353 |
} |
| ... | ... |
@@ -5,6 +5,7 @@ import ( |
| 5 | 5 |
"strings" |
| 6 | 6 |
|
| 7 | 7 |
"github.com/docker/docker/integration-cli/checker" |
| 8 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 8 | 9 |
"github.com/go-check/check" |
| 9 | 10 |
) |
| 10 | 11 |
|
| ... | ... |
@@ -13,7 +14,7 @@ func (s *DockerSuite) TestResizeAPIResponse(c *check.C) {
|
| 13 | 13 |
cleanedContainerID := strings.TrimSpace(out) |
| 14 | 14 |
|
| 15 | 15 |
endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40" |
| 16 |
- status, _, err := sockRequest("POST", endpoint, nil)
|
|
| 16 |
+ status, _, err := request.SockRequest("POST", endpoint, nil, daemonHost())
|
|
| 17 | 17 |
c.Assert(status, check.Equals, http.StatusOK) |
| 18 | 18 |
c.Assert(err, check.IsNil) |
| 19 | 19 |
} |
| ... | ... |
@@ -23,7 +24,7 @@ func (s *DockerSuite) TestResizeAPIHeightWidthNoInt(c *check.C) {
|
| 23 | 23 |
cleanedContainerID := strings.TrimSpace(out) |
| 24 | 24 |
|
| 25 | 25 |
endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar" |
| 26 |
- status, _, err := sockRequest("POST", endpoint, nil)
|
|
| 26 |
+ status, _, err := request.SockRequest("POST", endpoint, nil, daemonHost())
|
|
| 27 | 27 |
c.Assert(status, check.Equals, http.StatusInternalServerError) |
| 28 | 28 |
c.Assert(err, check.IsNil) |
| 29 | 29 |
} |
| ... | ... |
@@ -36,7 +37,7 @@ func (s *DockerSuite) TestResizeAPIResponseWhenContainerNotStarted(c *check.C) {
|
| 36 | 36 |
dockerCmd(c, "wait", cleanedContainerID) |
| 37 | 37 |
|
| 38 | 38 |
endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40" |
| 39 |
- status, body, err := sockRequest("POST", endpoint, nil)
|
|
| 39 |
+ status, body, err := request.SockRequest("POST", endpoint, nil, daemonHost())
|
|
| 40 | 40 |
c.Assert(status, check.Equals, http.StatusInternalServerError) |
| 41 | 41 |
c.Assert(err, check.IsNil) |
| 42 | 42 |
|
| ... | ... |
@@ -14,6 +14,7 @@ import ( |
| 14 | 14 |
"github.com/docker/docker/api/types" |
| 15 | 15 |
"github.com/docker/docker/api/types/versions" |
| 16 | 16 |
"github.com/docker/docker/integration-cli/checker" |
| 17 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 17 | 18 |
"github.com/go-check/check" |
| 18 | 19 |
) |
| 19 | 20 |
|
| ... | ... |
@@ -25,7 +26,7 @@ func (s *DockerSuite) TestAPIStatsNoStreamGetCpu(c *check.C) {
|
| 25 | 25 |
id := strings.TrimSpace(out) |
| 26 | 26 |
c.Assert(waitRun(id), checker.IsNil) |
| 27 | 27 |
|
| 28 |
- resp, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "")
|
|
| 28 |
+ resp, body, err := request.SockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "", daemonHost())
|
|
| 29 | 29 |
c.Assert(err, checker.IsNil) |
| 30 | 30 |
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK) |
| 31 | 31 |
c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json")
|
| ... | ... |
@@ -64,7 +65,7 @@ func (s *DockerSuite) TestAPIStatsStoppedContainerInGoroutines(c *check.C) {
|
| 64 | 64 |
id := strings.TrimSpace(out) |
| 65 | 65 |
|
| 66 | 66 |
getGoRoutines := func() int {
|
| 67 |
- _, body, err := sockRequestRaw("GET", fmt.Sprintf("/info"), nil, "")
|
|
| 67 |
+ _, body, err := request.SockRequestRaw("GET", fmt.Sprintf("/info"), nil, "", daemonHost())
|
|
| 68 | 68 |
c.Assert(err, checker.IsNil) |
| 69 | 69 |
info := types.Info{}
|
| 70 | 70 |
err = json.NewDecoder(body).Decode(&info) |
| ... | ... |
@@ -75,7 +76,7 @@ func (s *DockerSuite) TestAPIStatsStoppedContainerInGoroutines(c *check.C) {
|
| 75 | 75 |
|
| 76 | 76 |
// When the HTTP connection is closed, the number of goroutines should not increase. |
| 77 | 77 |
routines := getGoRoutines() |
| 78 |
- _, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats", id), nil, "")
|
|
| 78 |
+ _, body, err := request.SockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats", id), nil, "", daemonHost())
|
|
| 79 | 79 |
c.Assert(err, checker.IsNil) |
| 80 | 80 |
body.Close() |
| 81 | 81 |
|
| ... | ... |
@@ -191,7 +192,7 @@ func (s *DockerSuite) TestAPIStatsNetworkStatsVersioning(c *check.C) {
|
| 191 | 191 |
func getNetworkStats(c *check.C, id string) map[string]types.NetworkStats {
|
| 192 | 192 |
var st *types.StatsJSON |
| 193 | 193 |
|
| 194 |
- _, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "")
|
|
| 194 |
+ _, body, err := request.SockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "", daemonHost())
|
|
| 195 | 195 |
c.Assert(err, checker.IsNil) |
| 196 | 196 |
|
| 197 | 197 |
err = json.NewDecoder(body).Decode(&st) |
| ... | ... |
@@ -208,7 +209,7 @@ func getNetworkStats(c *check.C, id string) map[string]types.NetworkStats {
|
| 208 | 208 |
func getVersionedStats(c *check.C, id string, apiVersion string) map[string]interface{} {
|
| 209 | 209 |
stats := make(map[string]interface{})
|
| 210 | 210 |
|
| 211 |
- _, body, err := sockRequestRaw("GET", fmt.Sprintf("/%s/containers/%s/stats?stream=false", apiVersion, id), nil, "")
|
|
| 211 |
+ _, body, err := request.SockRequestRaw("GET", fmt.Sprintf("/%s/containers/%s/stats?stream=false", apiVersion, id), nil, "", daemonHost())
|
|
| 212 | 212 |
c.Assert(err, checker.IsNil) |
| 213 | 213 |
defer body.Close() |
| 214 | 214 |
|
| ... | ... |
@@ -261,11 +262,11 @@ func jsonBlobHasGTE121NetworkStats(blob map[string]interface{}) bool {
|
| 261 | 261 |
func (s *DockerSuite) TestAPIStatsContainerNotFound(c *check.C) {
|
| 262 | 262 |
testRequires(c, DaemonIsLinux) |
| 263 | 263 |
|
| 264 |
- status, _, err := sockRequest("GET", "/containers/nonexistent/stats", nil)
|
|
| 264 |
+ status, _, err := request.SockRequest("GET", "/containers/nonexistent/stats", nil, daemonHost())
|
|
| 265 | 265 |
c.Assert(err, checker.IsNil) |
| 266 | 266 |
c.Assert(status, checker.Equals, http.StatusNotFound) |
| 267 | 267 |
|
| 268 |
- status, _, err = sockRequest("GET", "/containers/nonexistent/stats?stream=0", nil)
|
|
| 268 |
+ status, _, err = request.SockRequest("GET", "/containers/nonexistent/stats?stream=0", nil, daemonHost())
|
|
| 269 | 269 |
c.Assert(err, checker.IsNil) |
| 270 | 270 |
c.Assert(status, checker.Equals, http.StatusNotFound) |
| 271 | 271 |
} |
| ... | ... |
@@ -283,7 +284,7 @@ func (s *DockerSuite) TestAPIStatsNoStreamConnectedContainers(c *check.C) {
|
| 283 | 283 |
|
| 284 | 284 |
ch := make(chan error) |
| 285 | 285 |
go func() {
|
| 286 |
- resp, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id2), nil, "")
|
|
| 286 |
+ resp, body, err := request.SockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id2), nil, "", daemonHost())
|
|
| 287 | 287 |
defer body.Close() |
| 288 | 288 |
if err != nil {
|
| 289 | 289 |
ch <- err |
| ... | ... |
@@ -9,13 +9,14 @@ import ( |
| 9 | 9 |
|
| 10 | 10 |
"github.com/docker/docker/api/types" |
| 11 | 11 |
"github.com/docker/docker/integration-cli/checker" |
| 12 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 12 | 13 |
"github.com/go-check/check" |
| 13 | 14 |
) |
| 14 | 15 |
|
| 15 | 16 |
func (s *DockerSuite) TestAPIStatsContainerGetMemoryLimit(c *check.C) {
|
| 16 | 17 |
testRequires(c, DaemonIsLinux, memoryLimitSupport) |
| 17 | 18 |
|
| 18 |
- resp, body, err := sockRequestRaw("GET", "/info", nil, "application/json")
|
|
| 19 |
+ resp, body, err := request.SockRequestRaw("GET", "/info", nil, "application/json", daemonHost())
|
|
| 19 | 20 |
c.Assert(err, checker.IsNil) |
| 20 | 21 |
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK) |
| 21 | 22 |
var info types.Info |
| ... | ... |
@@ -28,7 +29,7 @@ func (s *DockerSuite) TestAPIStatsContainerGetMemoryLimit(c *check.C) {
|
| 28 | 28 |
dockerCmd(c, "run", "-d", "--name", conName, "busybox", "top") |
| 29 | 29 |
c.Assert(waitRun(conName), checker.IsNil) |
| 30 | 30 |
|
| 31 |
- resp, body, err = sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", conName), nil, "")
|
|
| 31 |
+ resp, body, err = request.SockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", conName), nil, "", daemonHost())
|
|
| 32 | 32 |
c.Assert(err, checker.IsNil) |
| 33 | 33 |
c.Assert(resp.StatusCode, checker.Equals, http.StatusOK) |
| 34 | 34 |
c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json")
|
| ... | ... |
@@ -2,6 +2,7 @@ package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 |
+ "io/ioutil" |
|
| 5 | 6 |
"net/http" |
| 6 | 7 |
"net/http/httptest" |
| 7 | 8 |
"runtime" |
| ... | ... |
@@ -10,19 +11,20 @@ import ( |
| 10 | 10 |
|
| 11 | 11 |
"github.com/docker/docker/api" |
| 12 | 12 |
"github.com/docker/docker/integration-cli/checker" |
| 13 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 13 | 14 |
"github.com/docker/docker/pkg/testutil" |
| 14 | 15 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
| 15 | 16 |
"github.com/go-check/check" |
| 16 | 17 |
) |
| 17 | 18 |
|
| 18 | 19 |
func (s *DockerSuite) TestAPIOptionsRoute(c *check.C) {
|
| 19 |
- status, _, err := sockRequest("OPTIONS", "/", nil)
|
|
| 20 |
+ resp, _, err := request.Do(daemonHost(), "/", request.Method(http.MethodOptions)) |
|
| 20 | 21 |
c.Assert(err, checker.IsNil) |
| 21 |
- c.Assert(status, checker.Equals, http.StatusOK) |
|
| 22 |
+ c.Assert(resp.StatusCode, checker.Equals, http.StatusOK) |
|
| 22 | 23 |
} |
| 23 | 24 |
|
| 24 | 25 |
func (s *DockerSuite) TestAPIGetEnabledCORS(c *check.C) {
|
| 25 |
- res, body, err := sockRequestRaw("GET", "/version", nil, "")
|
|
| 26 |
+ res, body, err := request.SockRequestRaw("GET", "/version", nil, "", daemonHost())
|
|
| 26 | 27 |
c.Assert(err, checker.IsNil) |
| 27 | 28 |
c.Assert(res.StatusCode, checker.Equals, http.StatusOK) |
| 28 | 29 |
body.Close() |
| ... | ... |
@@ -47,11 +49,14 @@ func (s *DockerSuite) TestAPIClientVersionOldNotSupported(c *check.C) {
|
| 47 | 47 |
v[1] = strconv.Itoa(vMinInt) |
| 48 | 48 |
version := strings.Join(v, ".") |
| 49 | 49 |
|
| 50 |
- status, body, err := sockRequest("GET", "/v"+version+"/version", nil)
|
|
| 50 |
+ resp, body, err := request.Get(daemonHost(), "/v"+version+"/version") |
|
| 51 | 51 |
c.Assert(err, checker.IsNil) |
| 52 |
- c.Assert(status, checker.Equals, http.StatusBadRequest) |
|
| 52 |
+ defer body.Close() |
|
| 53 |
+ c.Assert(resp.StatusCode, checker.Equals, http.StatusBadRequest) |
|
| 53 | 54 |
expected := fmt.Sprintf("client version %s is too old. Minimum supported API version is %s, please upgrade your client to a newer version", version, api.MinVersion)
|
| 54 |
- c.Assert(strings.TrimSpace(string(body)), checker.Contains, expected) |
|
| 55 |
+ content, err := ioutil.ReadAll(body) |
|
| 56 |
+ c.Assert(err, checker.IsNil) |
|
| 57 |
+ c.Assert(strings.TrimSpace(string(content)), checker.Contains, expected) |
|
| 55 | 58 |
} |
| 56 | 59 |
|
| 57 | 60 |
func (s *DockerSuite) TestAPIDockerAPIVersion(c *check.C) {
|
| ... | ... |
@@ -75,7 +80,7 @@ func (s *DockerSuite) TestAPIDockerAPIVersion(c *check.C) {
|
| 75 | 75 |
} |
| 76 | 76 |
|
| 77 | 77 |
func (s *DockerSuite) TestAPIErrorJSON(c *check.C) {
|
| 78 |
- httpResp, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(`{}`), "application/json")
|
|
| 78 |
+ httpResp, body, err := request.Post(daemonHost(), "/containers/create", request.JSONBody(struct{}{}))
|
|
| 79 | 79 |
c.Assert(err, checker.IsNil) |
| 80 | 80 |
c.Assert(httpResp.StatusCode, checker.Equals, http.StatusInternalServerError) |
| 81 | 81 |
c.Assert(httpResp.Header.Get("Content-Type"), checker.Equals, "application/json")
|
| ... | ... |
@@ -88,7 +93,7 @@ func (s *DockerSuite) TestAPIErrorPlainText(c *check.C) {
|
| 88 | 88 |
// Windows requires API 1.25 or later. This test is validating a behaviour which was present |
| 89 | 89 |
// in v1.23, but changed in 1.24, hence not applicable on Windows. See apiVersionSupportsJSONErrors |
| 90 | 90 |
testRequires(c, DaemonIsLinux) |
| 91 |
- httpResp, body, err := sockRequestRaw("POST", "/v1.23/containers/create", strings.NewReader(`{}`), "application/json")
|
|
| 91 |
+ httpResp, body, err := request.Post(daemonHost(), "/v1.23/containers/create", request.JSONBody(struct{}{}))
|
|
| 92 | 92 |
c.Assert(err, checker.IsNil) |
| 93 | 93 |
c.Assert(httpResp.StatusCode, checker.Equals, http.StatusInternalServerError) |
| 94 | 94 |
c.Assert(httpResp.Header.Get("Content-Type"), checker.Contains, "text/plain")
|
| ... | ... |
@@ -99,7 +104,7 @@ func (s *DockerSuite) TestAPIErrorPlainText(c *check.C) {
|
| 99 | 99 |
|
| 100 | 100 |
func (s *DockerSuite) TestAPIErrorNotFoundJSON(c *check.C) {
|
| 101 | 101 |
// 404 is a different code path to normal errors, so test separately |
| 102 |
- httpResp, body, err := sockRequestRaw("GET", "/notfound", nil, "application/json")
|
|
| 102 |
+ httpResp, body, err := request.Get(daemonHost(), "/notfound", request.JSON) |
|
| 103 | 103 |
c.Assert(err, checker.IsNil) |
| 104 | 104 |
c.Assert(httpResp.StatusCode, checker.Equals, http.StatusNotFound) |
| 105 | 105 |
c.Assert(httpResp.Header.Get("Content-Type"), checker.Equals, "application/json")
|
| ... | ... |
@@ -109,7 +114,7 @@ func (s *DockerSuite) TestAPIErrorNotFoundJSON(c *check.C) {
|
| 109 | 109 |
} |
| 110 | 110 |
|
| 111 | 111 |
func (s *DockerSuite) TestAPIErrorNotFoundPlainText(c *check.C) {
|
| 112 |
- httpResp, body, err := sockRequestRaw("GET", "/v1.23/notfound", nil, "application/json")
|
|
| 112 |
+ httpResp, body, err := request.Get(daemonHost(), "/v1.23/notfound", request.JSON) |
|
| 113 | 113 |
c.Assert(err, checker.IsNil) |
| 114 | 114 |
c.Assert(httpResp.StatusCode, checker.Equals, http.StatusNotFound) |
| 115 | 115 |
c.Assert(httpResp.Header.Get("Content-Type"), checker.Contains, "text/plain")
|
| ... | ... |
@@ -6,6 +6,7 @@ import ( |
| 6 | 6 |
"strings" |
| 7 | 7 |
|
| 8 | 8 |
"github.com/docker/docker/integration-cli/checker" |
| 9 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 9 | 10 |
"github.com/go-check/check" |
| 10 | 11 |
) |
| 11 | 12 |
|
| ... | ... |
@@ -20,7 +21,7 @@ func (s *DockerSuite) TestAPIUpdateContainer(c *check.C) {
|
| 20 | 20 |
"MemorySwap": 524288000, |
| 21 | 21 |
} |
| 22 | 22 |
dockerCmd(c, "run", "-d", "--name", name, "-m", "200M", "busybox", "top") |
| 23 |
- _, _, err := sockRequest("POST", "/containers/"+name+"/update", hostConfig)
|
|
| 23 |
+ _, _, err := request.SockRequest("POST", "/containers/"+name+"/update", hostConfig, daemonHost())
|
|
| 24 | 24 |
c.Assert(err, check.IsNil) |
| 25 | 25 |
|
| 26 | 26 |
c.Assert(inspectField(c, name, "HostConfig.Memory"), checker.Equals, "314572800") |
| ... | ... |
@@ -7,11 +7,12 @@ import ( |
| 7 | 7 |
"github.com/docker/docker/api/types" |
| 8 | 8 |
"github.com/docker/docker/dockerversion" |
| 9 | 9 |
"github.com/docker/docker/integration-cli/checker" |
| 10 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 10 | 11 |
"github.com/go-check/check" |
| 11 | 12 |
) |
| 12 | 13 |
|
| 13 | 14 |
func (s *DockerSuite) TestGetVersion(c *check.C) {
|
| 14 |
- status, body, err := sockRequest("GET", "/version", nil)
|
|
| 15 |
+ status, body, err := request.SockRequest("GET", "/version", nil, daemonHost())
|
|
| 15 | 16 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 16 | 17 |
c.Assert(err, checker.IsNil) |
| 17 | 18 |
|
| ... | ... |
@@ -8,6 +8,7 @@ import ( |
| 8 | 8 |
"github.com/docker/docker/api/types" |
| 9 | 9 |
volumetypes "github.com/docker/docker/api/types/volume" |
| 10 | 10 |
"github.com/docker/docker/integration-cli/checker" |
| 11 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 11 | 12 |
"github.com/go-check/check" |
| 12 | 13 |
) |
| 13 | 14 |
|
| ... | ... |
@@ -15,7 +16,7 @@ func (s *DockerSuite) TestVolumesAPIList(c *check.C) {
|
| 15 | 15 |
prefix, _ := getPrefixAndSlashFromDaemonPlatform() |
| 16 | 16 |
dockerCmd(c, "run", "-v", prefix+"/foo", "busybox") |
| 17 | 17 |
|
| 18 |
- status, b, err := sockRequest("GET", "/volumes", nil)
|
|
| 18 |
+ status, b, err := request.SockRequest("GET", "/volumes", nil, daemonHost())
|
|
| 19 | 19 |
c.Assert(err, checker.IsNil) |
| 20 | 20 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 21 | 21 |
|
| ... | ... |
@@ -29,7 +30,7 @@ func (s *DockerSuite) TestVolumesAPICreate(c *check.C) {
|
| 29 | 29 |
config := volumetypes.VolumesCreateBody{
|
| 30 | 30 |
Name: "test", |
| 31 | 31 |
} |
| 32 |
- status, b, err := sockRequest("POST", "/volumes/create", config)
|
|
| 32 |
+ status, b, err := request.SockRequest("POST", "/volumes/create", config, daemonHost())
|
|
| 33 | 33 |
c.Assert(err, check.IsNil) |
| 34 | 34 |
c.Assert(status, check.Equals, http.StatusCreated, check.Commentf(string(b))) |
| 35 | 35 |
|
| ... | ... |
@@ -44,7 +45,7 @@ func (s *DockerSuite) TestVolumesAPIRemove(c *check.C) {
|
| 44 | 44 |
prefix, _ := getPrefixAndSlashFromDaemonPlatform() |
| 45 | 45 |
dockerCmd(c, "run", "-v", prefix+"/foo", "--name=test", "busybox") |
| 46 | 46 |
|
| 47 |
- status, b, err := sockRequest("GET", "/volumes", nil)
|
|
| 47 |
+ status, b, err := request.SockRequest("GET", "/volumes", nil, daemonHost())
|
|
| 48 | 48 |
c.Assert(err, checker.IsNil) |
| 49 | 49 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 50 | 50 |
|
| ... | ... |
@@ -53,12 +54,12 @@ func (s *DockerSuite) TestVolumesAPIRemove(c *check.C) {
|
| 53 | 53 |
c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
|
| 54 | 54 |
|
| 55 | 55 |
v := volumes.Volumes[0] |
| 56 |
- status, _, err = sockRequest("DELETE", "/volumes/"+v.Name, nil)
|
|
| 56 |
+ status, _, err = request.SockRequest("DELETE", "/volumes/"+v.Name, nil, daemonHost())
|
|
| 57 | 57 |
c.Assert(err, checker.IsNil) |
| 58 | 58 |
c.Assert(status, checker.Equals, http.StatusConflict, check.Commentf("Should not be able to remove a volume that is in use"))
|
| 59 | 59 |
|
| 60 | 60 |
dockerCmd(c, "rm", "-f", "test") |
| 61 |
- status, data, err := sockRequest("DELETE", "/volumes/"+v.Name, nil)
|
|
| 61 |
+ status, data, err := request.SockRequest("DELETE", "/volumes/"+v.Name, nil, daemonHost())
|
|
| 62 | 62 |
c.Assert(err, checker.IsNil) |
| 63 | 63 |
c.Assert(status, checker.Equals, http.StatusNoContent, check.Commentf(string(data))) |
| 64 | 64 |
|
| ... | ... |
@@ -68,11 +69,11 @@ func (s *DockerSuite) TestVolumesAPIInspect(c *check.C) {
|
| 68 | 68 |
config := volumetypes.VolumesCreateBody{
|
| 69 | 69 |
Name: "test", |
| 70 | 70 |
} |
| 71 |
- status, b, err := sockRequest("POST", "/volumes/create", config)
|
|
| 71 |
+ status, b, err := request.SockRequest("POST", "/volumes/create", config, daemonHost())
|
|
| 72 | 72 |
c.Assert(err, check.IsNil) |
| 73 | 73 |
c.Assert(status, check.Equals, http.StatusCreated, check.Commentf(string(b))) |
| 74 | 74 |
|
| 75 |
- status, b, err = sockRequest("GET", "/volumes", nil)
|
|
| 75 |
+ status, b, err = request.SockRequest("GET", "/volumes", nil, daemonHost())
|
|
| 76 | 76 |
c.Assert(err, checker.IsNil) |
| 77 | 77 |
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf(string(b))) |
| 78 | 78 |
|
| ... | ... |
@@ -81,7 +82,7 @@ func (s *DockerSuite) TestVolumesAPIInspect(c *check.C) {
|
| 81 | 81 |
c.Assert(len(volumes.Volumes), checker.Equals, 1, check.Commentf("\n%v", volumes.Volumes))
|
| 82 | 82 |
|
| 83 | 83 |
var vol types.Volume |
| 84 |
- status, b, err = sockRequest("GET", "/volumes/"+config.Name, nil)
|
|
| 84 |
+ status, b, err = request.SockRequest("GET", "/volumes/"+config.Name, nil, daemonHost())
|
|
| 85 | 85 |
c.Assert(err, checker.IsNil) |
| 86 | 86 |
c.Assert(status, checker.Equals, http.StatusOK, check.Commentf(string(b))) |
| 87 | 87 |
c.Assert(json.Unmarshal(b, &vol), checker.IsNil) |
| ... | ... |
@@ -15,6 +15,7 @@ import ( |
| 15 | 15 |
eventtypes "github.com/docker/docker/api/types/events" |
| 16 | 16 |
eventstestutils "github.com/docker/docker/daemon/events/testutils" |
| 17 | 17 |
"github.com/docker/docker/integration-cli/checker" |
| 18 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 18 | 19 |
"github.com/docker/docker/pkg/testutil" |
| 19 | 20 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
| 20 | 21 |
"github.com/go-check/check" |
| ... | ... |
@@ -494,7 +495,7 @@ func (s *DockerSuite) TestEventsResize(c *check.C) {
|
| 494 | 494 |
c.Assert(waitRun(cID), checker.IsNil) |
| 495 | 495 |
|
| 496 | 496 |
endpoint := "/containers/" + cID + "/resize?h=80&w=24" |
| 497 |
- status, _, err := sockRequest("POST", endpoint, nil)
|
|
| 497 |
+ status, _, err := request.SockRequest("POST", endpoint, nil, daemonHost())
|
|
| 498 | 498 |
c.Assert(status, checker.Equals, http.StatusOK) |
| 499 | 499 |
c.Assert(err, checker.IsNil) |
| 500 | 500 |
|
| ... | ... |
@@ -16,6 +16,7 @@ import ( |
| 16 | 16 |
"time" |
| 17 | 17 |
|
| 18 | 18 |
"github.com/docker/docker/integration-cli/checker" |
| 19 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 19 | 20 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
| 20 | 21 |
"github.com/go-check/check" |
| 21 | 22 |
) |
| ... | ... |
@@ -355,14 +356,14 @@ func (s *DockerSuite) TestExecInspectID(c *check.C) {
|
| 355 | 355 |
} |
| 356 | 356 |
|
| 357 | 357 |
// But we should still be able to query the execID |
| 358 |
- sc, body, err := sockRequest("GET", "/exec/"+execID+"/json", nil)
|
|
| 358 |
+ sc, body, err := request.SockRequest("GET", "/exec/"+execID+"/json", nil, daemonHost())
|
|
| 359 | 359 |
c.Assert(sc, checker.Equals, http.StatusOK, check.Commentf("received status != 200 OK: %d\n%s", sc, body))
|
| 360 | 360 |
|
| 361 | 361 |
// Now delete the container and then an 'inspect' on the exec should |
| 362 | 362 |
// result in a 404 (not 'container not running') |
| 363 | 363 |
out, ec := dockerCmd(c, "rm", "-f", id) |
| 364 | 364 |
c.Assert(ec, checker.Equals, 0, check.Commentf("error removing container: %s", out))
|
| 365 |
- sc, body, err = sockRequest("GET", "/exec/"+execID+"/json", nil)
|
|
| 365 |
+ sc, body, err = request.SockRequest("GET", "/exec/"+execID+"/json", nil, daemonHost())
|
|
| 366 | 366 |
c.Assert(sc, checker.Equals, http.StatusNotFound, check.Commentf("received status != 404: %d\n%s", sc, body))
|
| 367 | 367 |
} |
| 368 | 368 |
|
| ... | ... |
@@ -7,6 +7,7 @@ import ( |
| 7 | 7 |
"time" |
| 8 | 8 |
|
| 9 | 9 |
"github.com/docker/docker/integration-cli/checker" |
| 10 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 10 | 11 |
"github.com/go-check/check" |
| 11 | 12 |
) |
| 12 | 13 |
|
| ... | ... |
@@ -128,7 +129,7 @@ func (s *DockerSuite) TestKillStoppedContainerAPIPre120(c *check.C) {
|
| 128 | 128 |
runSleepingContainer(c, "--name", "docker-kill-test-api", "-d") |
| 129 | 129 |
dockerCmd(c, "stop", "docker-kill-test-api") |
| 130 | 130 |
|
| 131 |
- status, _, err := sockRequest("POST", fmt.Sprintf("/v1.19/containers/%s/kill", "docker-kill-test-api"), nil)
|
|
| 131 |
+ status, _, err := request.SockRequest("POST", fmt.Sprintf("/v1.19/containers/%s/kill", "docker-kill-test-api"), nil, daemonHost())
|
|
| 132 | 132 |
c.Assert(err, check.IsNil) |
| 133 | 133 |
c.Assert(status, check.Equals, http.StatusNoContent) |
| 134 | 134 |
} |
| ... | ... |
@@ -5,15 +5,16 @@ package main |
| 5 | 5 |
import ( |
| 6 | 6 |
"encoding/json" |
| 7 | 7 |
"fmt" |
| 8 |
- "github.com/kr/pty" |
|
| 9 | 8 |
"os/exec" |
| 10 | 9 |
"strings" |
| 11 | 10 |
"time" |
| 12 | 11 |
|
| 13 | 12 |
"github.com/docker/docker/api/types" |
| 14 | 13 |
"github.com/docker/docker/integration-cli/checker" |
| 14 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 15 | 15 |
"github.com/docker/docker/pkg/parsers/kernel" |
| 16 | 16 |
"github.com/go-check/check" |
| 17 |
+ "github.com/kr/pty" |
|
| 17 | 18 |
) |
| 18 | 19 |
|
| 19 | 20 |
func (s *DockerSuite) TestUpdateRunningContainer(c *check.C) {
|
| ... | ... |
@@ -219,7 +220,7 @@ func (s *DockerSuite) TestUpdateStats(c *check.C) {
|
| 219 | 219 |
c.Assert(waitRun(name), checker.IsNil) |
| 220 | 220 |
|
| 221 | 221 |
getMemLimit := func(id string) uint64 {
|
| 222 |
- resp, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "")
|
|
| 222 |
+ resp, body, err := request.SockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "", daemonHost())
|
|
| 223 | 223 |
c.Assert(err, checker.IsNil) |
| 224 | 224 |
c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json")
|
| 225 | 225 |
|
| ... | ... |
@@ -8,6 +8,7 @@ import ( |
| 8 | 8 |
"strings" |
| 9 | 9 |
|
| 10 | 10 |
"github.com/docker/docker/integration-cli/checker" |
| 11 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 11 | 12 |
"github.com/docker/docker/pkg/testutil" |
| 12 | 13 |
"github.com/go-check/check" |
| 13 | 14 |
) |
| ... | ... |
@@ -22,7 +23,7 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartHostConfig(c *check.C) {
|
| 22 | 22 |
config := map[string]interface{}{
|
| 23 | 23 |
"Binds": []string{"/aa:/bb"},
|
| 24 | 24 |
} |
| 25 |
- status, body, err := sockRequest("POST", "/containers/"+name+"/start", config)
|
|
| 25 |
+ status, body, err := request.SockRequest("POST", "/containers/"+name+"/start", config, daemonHost())
|
|
| 26 | 26 |
c.Assert(err, checker.IsNil) |
| 27 | 27 |
c.Assert(status, checker.Equals, http.StatusBadRequest) |
| 28 | 28 |
c.Assert(string(body), checker.Contains, "was deprecated since v1.10") |
| ... | ... |
@@ -41,7 +42,7 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumeBinds(c *check.C) {
|
| 41 | 41 |
"Volumes": map[string]struct{}{path: {}},
|
| 42 | 42 |
} |
| 43 | 43 |
|
| 44 |
- status, _, err := sockRequest("POST", formatV123StartAPIURL("/containers/create?name="+name), config)
|
|
| 44 |
+ status, _, err := request.SockRequest("POST", formatV123StartAPIURL("/containers/create?name="+name), config, daemonHost())
|
|
| 45 | 45 |
c.Assert(err, checker.IsNil) |
| 46 | 46 |
c.Assert(status, checker.Equals, http.StatusCreated) |
| 47 | 47 |
|
| ... | ... |
@@ -49,7 +50,7 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumeBinds(c *check.C) {
|
| 49 | 49 |
config = map[string]interface{}{
|
| 50 | 50 |
"Binds": []string{bindPath + ":" + path},
|
| 51 | 51 |
} |
| 52 |
- status, _, err = sockRequest("POST", formatV123StartAPIURL("/containers/"+name+"/start"), config)
|
|
| 52 |
+ status, _, err = request.SockRequest("POST", formatV123StartAPIURL("/containers/"+name+"/start"), config, daemonHost())
|
|
| 53 | 53 |
c.Assert(err, checker.IsNil) |
| 54 | 54 |
c.Assert(status, checker.Equals, http.StatusNoContent) |
| 55 | 55 |
|
| ... | ... |
@@ -68,7 +69,7 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartDupVolumeBinds(c *check.C) |
| 68 | 68 |
"Volumes": map[string]struct{}{"/tmp": {}},
|
| 69 | 69 |
} |
| 70 | 70 |
|
| 71 |
- status, _, err := sockRequest("POST", formatV123StartAPIURL("/containers/create?name="+name), config)
|
|
| 71 |
+ status, _, err := request.SockRequest("POST", formatV123StartAPIURL("/containers/create?name="+name), config, daemonHost())
|
|
| 72 | 72 |
c.Assert(err, checker.IsNil) |
| 73 | 73 |
c.Assert(status, checker.Equals, http.StatusCreated) |
| 74 | 74 |
|
| ... | ... |
@@ -78,7 +79,7 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartDupVolumeBinds(c *check.C) |
| 78 | 78 |
config = map[string]interface{}{
|
| 79 | 79 |
"Binds": []string{bindPath1 + ":/tmp", bindPath2 + ":/tmp"},
|
| 80 | 80 |
} |
| 81 |
- status, body, err := sockRequest("POST", formatV123StartAPIURL("/containers/"+name+"/start"), config)
|
|
| 81 |
+ status, body, err := request.SockRequest("POST", formatV123StartAPIURL("/containers/"+name+"/start"), config, daemonHost())
|
|
| 82 | 82 |
c.Assert(err, checker.IsNil) |
| 83 | 83 |
c.Assert(status, checker.Equals, http.StatusInternalServerError) |
| 84 | 84 |
c.Assert(string(body), checker.Contains, "Duplicate mount point", check.Commentf("Expected failure due to duplicate bind mounts to same path, instead got: %q with error: %v", string(body), err))
|
| ... | ... |
@@ -98,14 +99,14 @@ func (s *DockerSuite) TestDeprecatedContainerAPIStartVolumesFrom(c *check.C) {
|
| 98 | 98 |
"Volumes": map[string]struct{}{volPath: {}},
|
| 99 | 99 |
} |
| 100 | 100 |
|
| 101 |
- status, _, err := sockRequest("POST", formatV123StartAPIURL("/containers/create?name="+name), config)
|
|
| 101 |
+ status, _, err := request.SockRequest("POST", formatV123StartAPIURL("/containers/create?name="+name), config, daemonHost())
|
|
| 102 | 102 |
c.Assert(err, checker.IsNil) |
| 103 | 103 |
c.Assert(status, checker.Equals, http.StatusCreated) |
| 104 | 104 |
|
| 105 | 105 |
config = map[string]interface{}{
|
| 106 | 106 |
"VolumesFrom": []string{volName},
|
| 107 | 107 |
} |
| 108 |
- status, _, err = sockRequest("POST", formatV123StartAPIURL("/containers/"+name+"/start"), config)
|
|
| 108 |
+ status, _, err = request.SockRequest("POST", formatV123StartAPIURL("/containers/"+name+"/start"), config, daemonHost())
|
|
| 109 | 109 |
c.Assert(err, checker.IsNil) |
| 110 | 110 |
c.Assert(status, checker.Equals, http.StatusNoContent) |
| 111 | 111 |
|
| ... | ... |
@@ -128,7 +129,7 @@ func (s *DockerSuite) TestDeprecatedPostContainerBindNormalVolume(c *check.C) {
|
| 128 | 128 |
dockerCmd(c, "create", "-v", "/foo", "--name=two", "busybox") |
| 129 | 129 |
|
| 130 | 130 |
bindSpec := map[string][]string{"Binds": {fooDir + ":/foo"}}
|
| 131 |
- status, _, err := sockRequest("POST", formatV123StartAPIURL("/containers/two/start"), bindSpec)
|
|
| 131 |
+ status, _, err := request.SockRequest("POST", formatV123StartAPIURL("/containers/two/start"), bindSpec, daemonHost())
|
|
| 132 | 132 |
c.Assert(err, checker.IsNil) |
| 133 | 133 |
c.Assert(status, checker.Equals, http.StatusNoContent) |
| 134 | 134 |
|
| ... | ... |
@@ -149,7 +150,7 @@ func (s *DockerSuite) TestDeprecatedStartWithTooLowMemoryLimit(c *check.C) {
|
| 149 | 149 |
"Memory": 524287 |
| 150 | 150 |
}` |
| 151 | 151 |
|
| 152 |
- res, body, err := sockRequestRaw("POST", formatV123StartAPIURL("/containers/"+containerID+"/start"), strings.NewReader(config), "application/json")
|
|
| 152 |
+ res, body, err := request.SockRequestRaw("POST", formatV123StartAPIURL("/containers/"+containerID+"/start"), strings.NewReader(config), "application/json", daemonHost())
|
|
| 153 | 153 |
c.Assert(err, checker.IsNil) |
| 154 | 154 |
b, err2 := testutil.ReadBody(body) |
| 155 | 155 |
c.Assert(err2, checker.IsNil) |
| ... | ... |
@@ -168,7 +169,7 @@ func (s *DockerSuite) TestDeprecatedPostContainersStartWithoutLinksInHostConfig( |
| 168 | 168 |
hc := inspectFieldJSON(c, name, "HostConfig") |
| 169 | 169 |
config := `{"HostConfig":` + hc + `}`
|
| 170 | 170 |
|
| 171 |
- res, b, err := sockRequestRaw("POST", formatV123StartAPIURL("/containers/"+name+"/start"), strings.NewReader(config), "application/json")
|
|
| 171 |
+ res, b, err := request.SockRequestRaw("POST", formatV123StartAPIURL("/containers/"+name+"/start"), strings.NewReader(config), "application/json", daemonHost())
|
|
| 172 | 172 |
c.Assert(err, checker.IsNil) |
| 173 | 173 |
c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent) |
| 174 | 174 |
b.Close() |
| ... | ... |
@@ -186,7 +187,7 @@ func (s *DockerSuite) TestDeprecatedPostContainersStartWithLinksInHostConfig(c * |
| 186 | 186 |
hc := inspectFieldJSON(c, name, "HostConfig") |
| 187 | 187 |
config := `{"HostConfig":` + hc + `}`
|
| 188 | 188 |
|
| 189 |
- res, b, err := sockRequestRaw("POST", formatV123StartAPIURL("/containers/"+name+"/start"), strings.NewReader(config), "application/json")
|
|
| 189 |
+ res, b, err := request.SockRequestRaw("POST", formatV123StartAPIURL("/containers/"+name+"/start"), strings.NewReader(config), "application/json", daemonHost())
|
|
| 190 | 190 |
c.Assert(err, checker.IsNil) |
| 191 | 191 |
c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent) |
| 192 | 192 |
b.Close() |
| ... | ... |
@@ -204,7 +205,7 @@ func (s *DockerSuite) TestDeprecatedPostContainersStartWithLinksInHostConfigIdLi |
| 204 | 204 |
hc := inspectFieldJSON(c, name, "HostConfig") |
| 205 | 205 |
config := `{"HostConfig":` + hc + `}`
|
| 206 | 206 |
|
| 207 |
- res, b, err := sockRequestRaw("POST", formatV123StartAPIURL("/containers/"+name+"/start"), strings.NewReader(config), "application/json")
|
|
| 207 |
+ res, b, err := request.SockRequestRaw("POST", formatV123StartAPIURL("/containers/"+name+"/start"), strings.NewReader(config), "application/json", daemonHost())
|
|
| 208 | 208 |
c.Assert(err, checker.IsNil) |
| 209 | 209 |
c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent) |
| 210 | 210 |
b.Close() |
| ... | ... |
@@ -218,7 +219,7 @@ func (s *DockerSuite) TestDeprecatedStartWithNilDNS(c *check.C) {
|
| 218 | 218 |
|
| 219 | 219 |
config := `{"HostConfig": {"Dns": null}}`
|
| 220 | 220 |
|
| 221 |
- res, b, err := sockRequestRaw("POST", formatV123StartAPIURL("/containers/"+containerID+"/start"), strings.NewReader(config), "application/json")
|
|
| 221 |
+ res, b, err := request.SockRequestRaw("POST", formatV123StartAPIURL("/containers/"+containerID+"/start"), strings.NewReader(config), "application/json", daemonHost())
|
|
| 222 | 222 |
c.Assert(err, checker.IsNil) |
| 223 | 223 |
c.Assert(res.StatusCode, checker.Equals, http.StatusNoContent) |
| 224 | 224 |
b.Close() |
| ... | ... |
@@ -6,6 +6,7 @@ import ( |
| 6 | 6 |
"fmt" |
| 7 | 7 |
|
| 8 | 8 |
"github.com/docker/docker/integration-cli/checker" |
| 9 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 9 | 10 |
"github.com/go-check/check" |
| 10 | 11 |
) |
| 11 | 12 |
|
| ... | ... |
@@ -21,7 +22,7 @@ func (s *DockerNetworkSuite) TestDeprecatedDockerNetworkStartAPIWithHostconfig(c |
| 21 | 21 |
"NetworkMode": netName, |
| 22 | 22 |
}, |
| 23 | 23 |
} |
| 24 |
- _, _, err := sockRequest("POST", formatV123StartAPIURL("/containers/"+conName+"/start"), config)
|
|
| 24 |
+ _, _, err := request.SockRequest("POST", formatV123StartAPIURL("/containers/"+conName+"/start"), config, daemonHost())
|
|
| 25 | 25 |
c.Assert(err, checker.IsNil) |
| 26 | 26 |
c.Assert(waitRun(conName), checker.IsNil) |
| 27 | 27 |
networks := inspectField(c, conName, "NetworkSettings.Networks") |
| ... | ... |
@@ -1,7 +1,6 @@ |
| 1 | 1 |
package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "bufio" |
|
| 5 | 4 |
"bytes" |
| 6 | 5 |
"encoding/json" |
| 7 | 6 |
"errors" |
| ... | ... |
@@ -11,7 +10,6 @@ import ( |
| 11 | 11 |
"net" |
| 12 | 12 |
"net/http" |
| 13 | 13 |
"net/http/httptest" |
| 14 |
- "net/http/httputil" |
|
| 15 | 14 |
"net/url" |
| 16 | 15 |
"os" |
| 17 | 16 |
"os/exec" |
| ... | ... |
@@ -26,10 +24,9 @@ import ( |
| 26 | 26 |
"github.com/docker/docker/integration-cli/checker" |
| 27 | 27 |
"github.com/docker/docker/integration-cli/daemon" |
| 28 | 28 |
"github.com/docker/docker/integration-cli/registry" |
| 29 |
+ "github.com/docker/docker/integration-cli/request" |
|
| 29 | 30 |
"github.com/docker/docker/opts" |
| 30 |
- "github.com/docker/docker/pkg/ioutils" |
|
| 31 | 31 |
"github.com/docker/docker/pkg/stringutils" |
| 32 |
- "github.com/docker/docker/pkg/testutil" |
|
| 33 | 32 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
| 34 | 33 |
"github.com/go-check/check" |
| 35 | 34 |
) |
| ... | ... |
@@ -42,82 +39,6 @@ func daemonHost() string {
|
| 42 | 42 |
return daemonURLStr |
| 43 | 43 |
} |
| 44 | 44 |
|
| 45 |
-// FIXME(vdemeester) should probably completely move to daemon struct/methods |
|
| 46 |
-func sockConn(timeout time.Duration, daemonStr string) (net.Conn, error) {
|
|
| 47 |
- if daemonStr == "" {
|
|
| 48 |
- daemonStr = daemonHost() |
|
| 49 |
- } |
|
| 50 |
- return daemon.SockConn(timeout, daemonStr) |
|
| 51 |
-} |
|
| 52 |
- |
|
| 53 |
-func sockRequest(method, endpoint string, data interface{}) (int, []byte, error) {
|
|
| 54 |
- jsonData := bytes.NewBuffer(nil) |
|
| 55 |
- if err := json.NewEncoder(jsonData).Encode(data); err != nil {
|
|
| 56 |
- return -1, nil, err |
|
| 57 |
- } |
|
| 58 |
- |
|
| 59 |
- res, body, err := sockRequestRaw(method, endpoint, jsonData, "application/json") |
|
| 60 |
- if err != nil {
|
|
| 61 |
- return -1, nil, err |
|
| 62 |
- } |
|
| 63 |
- b, err := testutil.ReadBody(body) |
|
| 64 |
- return res.StatusCode, b, err |
|
| 65 |
-} |
|
| 66 |
- |
|
| 67 |
-func sockRequestRaw(method, endpoint string, data io.Reader, ct string) (*http.Response, io.ReadCloser, error) {
|
|
| 68 |
- return sockRequestRawToDaemon(method, endpoint, data, ct, "") |
|
| 69 |
-} |
|
| 70 |
- |
|
| 71 |
-func sockRequestRawToDaemon(method, endpoint string, data io.Reader, ct, daemon string) (*http.Response, io.ReadCloser, error) {
|
|
| 72 |
- req, client, err := newRequestClient(method, endpoint, data, ct, daemon) |
|
| 73 |
- if err != nil {
|
|
| 74 |
- return nil, nil, err |
|
| 75 |
- } |
|
| 76 |
- |
|
| 77 |
- resp, err := client.Do(req) |
|
| 78 |
- if err != nil {
|
|
| 79 |
- client.Close() |
|
| 80 |
- return nil, nil, err |
|
| 81 |
- } |
|
| 82 |
- body := ioutils.NewReadCloserWrapper(resp.Body, func() error {
|
|
| 83 |
- defer resp.Body.Close() |
|
| 84 |
- return client.Close() |
|
| 85 |
- }) |
|
| 86 |
- |
|
| 87 |
- return resp, body, nil |
|
| 88 |
-} |
|
| 89 |
- |
|
| 90 |
-func sockRequestHijack(method, endpoint string, data io.Reader, ct string) (net.Conn, *bufio.Reader, error) {
|
|
| 91 |
- req, client, err := newRequestClient(method, endpoint, data, ct, "") |
|
| 92 |
- if err != nil {
|
|
| 93 |
- return nil, nil, err |
|
| 94 |
- } |
|
| 95 |
- |
|
| 96 |
- client.Do(req) |
|
| 97 |
- conn, br := client.Hijack() |
|
| 98 |
- return conn, br, nil |
|
| 99 |
-} |
|
| 100 |
- |
|
| 101 |
-func newRequestClient(method, endpoint string, data io.Reader, ct, daemon string) (*http.Request, *httputil.ClientConn, error) {
|
|
| 102 |
- c, err := sockConn(time.Duration(10*time.Second), daemon) |
|
| 103 |
- if err != nil {
|
|
| 104 |
- return nil, nil, fmt.Errorf("could not dial docker daemon: %v", err)
|
|
| 105 |
- } |
|
| 106 |
- |
|
| 107 |
- client := httputil.NewClientConn(c, nil) |
|
| 108 |
- |
|
| 109 |
- req, err := http.NewRequest(method, endpoint, data) |
|
| 110 |
- if err != nil {
|
|
| 111 |
- client.Close() |
|
| 112 |
- return nil, nil, fmt.Errorf("could not create new request: %v", err)
|
|
| 113 |
- } |
|
| 114 |
- |
|
| 115 |
- if ct != "" {
|
|
| 116 |
- req.Header.Set("Content-Type", ct)
|
|
| 117 |
- } |
|
| 118 |
- return req, client, nil |
|
| 119 |
-} |
|
| 120 |
- |
|
| 121 | 45 |
// FIXME(vdemeester) move this away are remove ignoreNoSuchContainer bool |
| 122 | 46 |
func deleteContainer(ignoreNoSuchContainer bool, container ...string) error {
|
| 123 | 47 |
result := icmd.RunCommand(dockerBinary, append([]string{"rm", "-fv"}, container...)...)
|
| ... | ... |
@@ -163,7 +84,7 @@ func deleteAllNetworks(c *check.C) {
|
| 163 | 163 |
// nat is a pre-defined network on Windows and cannot be removed |
| 164 | 164 |
continue |
| 165 | 165 |
} |
| 166 |
- status, b, err := sockRequest("DELETE", "/networks/"+n.Name, nil)
|
|
| 166 |
+ status, b, err := request.SockRequest("DELETE", "/networks/"+n.Name, nil, daemonHost())
|
|
| 167 | 167 |
if err != nil {
|
| 168 | 168 |
errs = append(errs, err.Error()) |
| 169 | 169 |
continue |
| ... | ... |
@@ -177,7 +98,7 @@ func deleteAllNetworks(c *check.C) {
|
| 177 | 177 |
|
| 178 | 178 |
func getAllNetworks() ([]types.NetworkResource, error) {
|
| 179 | 179 |
var networks []types.NetworkResource |
| 180 |
- _, b, err := sockRequest("GET", "/networks", nil)
|
|
| 180 |
+ _, b, err := request.SockRequest("GET", "/networks", nil, daemonHost())
|
|
| 181 | 181 |
if err != nil {
|
| 182 | 182 |
return nil, err |
| 183 | 183 |
} |
| ... | ... |
@@ -193,7 +114,7 @@ func deleteAllPlugins(c *check.C) {
|
| 193 | 193 |
var errs []string |
| 194 | 194 |
for _, p := range plugins {
|
| 195 | 195 |
pluginName := p.Name |
| 196 |
- status, b, err := sockRequest("DELETE", "/plugins/"+pluginName+"?force=1", nil)
|
|
| 196 |
+ status, b, err := request.SockRequest("DELETE", "/plugins/"+pluginName+"?force=1", nil, daemonHost())
|
|
| 197 | 197 |
if err != nil {
|
| 198 | 198 |
errs = append(errs, err.Error()) |
| 199 | 199 |
continue |
| ... | ... |
@@ -207,7 +128,7 @@ func deleteAllPlugins(c *check.C) {
|
| 207 | 207 |
|
| 208 | 208 |
func getAllPlugins() (types.PluginsListResponse, error) {
|
| 209 | 209 |
var plugins types.PluginsListResponse |
| 210 |
- _, b, err := sockRequest("GET", "/plugins", nil)
|
|
| 210 |
+ _, b, err := request.SockRequest("GET", "/plugins", nil, daemonHost())
|
|
| 211 | 211 |
if err != nil {
|
| 212 | 212 |
return nil, err |
| 213 | 213 |
} |
| ... | ... |
@@ -222,7 +143,7 @@ func deleteAllVolumes(c *check.C) {
|
| 222 | 222 |
c.Assert(err, checker.IsNil) |
| 223 | 223 |
var errs []string |
| 224 | 224 |
for _, v := range volumes {
|
| 225 |
- status, b, err := sockRequest("DELETE", "/volumes/"+v.Name, nil)
|
|
| 225 |
+ status, b, err := request.SockRequest("DELETE", "/volumes/"+v.Name, nil, daemonHost())
|
|
| 226 | 226 |
if err != nil {
|
| 227 | 227 |
errs = append(errs, err.Error()) |
| 228 | 228 |
continue |
| ... | ... |
@@ -236,7 +157,7 @@ func deleteAllVolumes(c *check.C) {
|
| 236 | 236 |
|
| 237 | 237 |
func getAllVolumes() ([]*types.Volume, error) {
|
| 238 | 238 |
var volumes volumetypes.VolumesListOKBody |
| 239 |
- _, b, err := sockRequest("GET", "/volumes", nil)
|
|
| 239 |
+ _, b, err := request.SockRequest("GET", "/volumes", nil, daemonHost())
|
|
| 240 | 240 |
if err != nil {
|
| 241 | 241 |
return nil, err |
| 242 | 242 |
} |
| ... | ... |
@@ -1066,7 +987,7 @@ func daemonTime(c *check.C) time.Time {
|
| 1066 | 1066 |
return time.Now() |
| 1067 | 1067 |
} |
| 1068 | 1068 |
|
| 1069 |
- status, body, err := sockRequest("GET", "/info", nil)
|
|
| 1069 |
+ status, body, err := request.SockRequest("GET", "/info", nil, daemonHost())
|
|
| 1070 | 1070 |
c.Assert(err, check.IsNil) |
| 1071 | 1071 |
c.Assert(status, check.Equals, http.StatusOK) |
| 1072 | 1072 |
|
| ... | ... |
@@ -1192,7 +1113,7 @@ func waitInspectWithArgs(name, expr, expected string, timeout time.Duration, arg |
| 1192 | 1192 |
|
| 1193 | 1193 |
func getInspectBody(c *check.C, version, id string) []byte {
|
| 1194 | 1194 |
endpoint := fmt.Sprintf("/%s/containers/%s/json", version, id)
|
| 1195 |
- status, body, err := sockRequest("GET", endpoint, nil)
|
|
| 1195 |
+ status, body, err := request.SockRequest("GET", endpoint, nil, daemonHost())
|
|
| 1196 | 1196 |
c.Assert(err, check.IsNil) |
| 1197 | 1197 |
c.Assert(status, check.Equals, http.StatusOK) |
| 1198 | 1198 |
return body |
| ... | ... |
@@ -1224,7 +1145,7 @@ func getGoroutineNumber() (int, error) {
|
| 1224 | 1224 |
i := struct {
|
| 1225 | 1225 |
NGoroutines int |
| 1226 | 1226 |
}{}
|
| 1227 |
- status, b, err := sockRequest("GET", "/info", nil)
|
|
| 1227 |
+ status, b, err := request.SockRequest("GET", "/info", nil, daemonHost())
|
|
| 1228 | 1228 |
if err != nil {
|
| 1229 | 1229 |
return 0, err |
| 1230 | 1230 |
} |
| 0 | 12 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,263 @@ |
| 0 |
+package request |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "bufio" |
|
| 4 |
+ "bytes" |
|
| 5 |
+ "crypto/tls" |
|
| 6 |
+ "encoding/json" |
|
| 7 |
+ "fmt" |
|
| 8 |
+ "io" |
|
| 9 |
+ "io/ioutil" |
|
| 10 |
+ "net" |
|
| 11 |
+ "net/http" |
|
| 12 |
+ "net/http/httputil" |
|
| 13 |
+ "net/url" |
|
| 14 |
+ "os" |
|
| 15 |
+ "path/filepath" |
|
| 16 |
+ "time" |
|
| 17 |
+ |
|
| 18 |
+ dclient "github.com/docker/docker/client" |
|
| 19 |
+ "github.com/docker/docker/pkg/ioutils" |
|
| 20 |
+ "github.com/docker/docker/pkg/testutil" |
|
| 21 |
+ "github.com/docker/go-connections/sockets" |
|
| 22 |
+ "github.com/docker/go-connections/tlsconfig" |
|
| 23 |
+ "github.com/pkg/errors" |
|
| 24 |
+) |
|
| 25 |
+ |
|
| 26 |
+// Method creates a modifier that sets the specified string as the request method |
|
| 27 |
+func Method(method string) func(*http.Request) error {
|
|
| 28 |
+ return func(req *http.Request) error {
|
|
| 29 |
+ req.Method = method |
|
| 30 |
+ return nil |
|
| 31 |
+ } |
|
| 32 |
+} |
|
| 33 |
+ |
|
| 34 |
+// JSON sets the Content-Type request header to json |
|
| 35 |
+func JSON(req *http.Request) error {
|
|
| 36 |
+ req.Header.Set("Content-Type", "application/json")
|
|
| 37 |
+ return nil |
|
| 38 |
+} |
|
| 39 |
+ |
|
| 40 |
+// JSONBody creates a modifier that encodes the specified data to a JSON string and set it as request body. It also sets |
|
| 41 |
+// the Content-Type header of the request. |
|
| 42 |
+func JSONBody(data interface{}) func(*http.Request) error {
|
|
| 43 |
+ return func(req *http.Request) error {
|
|
| 44 |
+ jsonData := bytes.NewBuffer(nil) |
|
| 45 |
+ if err := json.NewEncoder(jsonData).Encode(data); err != nil {
|
|
| 46 |
+ return err |
|
| 47 |
+ } |
|
| 48 |
+ req.Body = ioutil.NopCloser(jsonData) |
|
| 49 |
+ req.Header.Set("Content-Type", "application/json")
|
|
| 50 |
+ return nil |
|
| 51 |
+ } |
|
| 52 |
+} |
|
| 53 |
+ |
|
| 54 |
+// Post creates and execute a POST request on the specified host and endpoint, with the specified request modifiers |
|
| 55 |
+func Post(host, endpoint string, modifiers ...func(*http.Request) error) (*http.Response, io.ReadCloser, error) {
|
|
| 56 |
+ return Do(host, endpoint, append(modifiers, Method(http.MethodPost))...) |
|
| 57 |
+} |
|
| 58 |
+ |
|
| 59 |
+// Delete creates and execute a DELETE request on the specified host and endpoint, with the specified request modifiers |
|
| 60 |
+func Delete(host, endpoint string, modifiers ...func(*http.Request) error) (*http.Response, io.ReadCloser, error) {
|
|
| 61 |
+ return Do(host, endpoint, append(modifiers, Method(http.MethodDelete))...) |
|
| 62 |
+} |
|
| 63 |
+ |
|
| 64 |
+// Get creates and execute a GET request on the specified host and endpoint, with the specified request modifiers |
|
| 65 |
+func Get(host, endpoint string, modifiers ...func(*http.Request) error) (*http.Response, io.ReadCloser, error) {
|
|
| 66 |
+ return Do(host, endpoint, modifiers...) |
|
| 67 |
+} |
|
| 68 |
+ |
|
| 69 |
+// Do creates and execute a request on the specified host and endpoint, with the specified request modifiers |
|
| 70 |
+func Do(host, endpoint string, modifiers ...func(*http.Request) error) (*http.Response, io.ReadCloser, error) {
|
|
| 71 |
+ req, err := New(host, endpoint, modifiers...) |
|
| 72 |
+ if err != nil {
|
|
| 73 |
+ return nil, nil, err |
|
| 74 |
+ } |
|
| 75 |
+ client, err := NewClient(host) |
|
| 76 |
+ if err != nil {
|
|
| 77 |
+ return nil, nil, err |
|
| 78 |
+ } |
|
| 79 |
+ resp, err := client.Do(req) |
|
| 80 |
+ var body io.ReadCloser |
|
| 81 |
+ if resp != nil {
|
|
| 82 |
+ body = ioutils.NewReadCloserWrapper(resp.Body, func() error {
|
|
| 83 |
+ defer resp.Body.Close() |
|
| 84 |
+ return nil |
|
| 85 |
+ }) |
|
| 86 |
+ } |
|
| 87 |
+ return resp, body, err |
|
| 88 |
+} |
|
| 89 |
+ |
|
| 90 |
+// New creates a new http Request to the specified host and endpoint, with the specified request modifiers |
|
| 91 |
+func New(host, endpoint string, modifiers ...func(*http.Request) error) (*http.Request, error) {
|
|
| 92 |
+ _, addr, _, err := dclient.ParseHost(host) |
|
| 93 |
+ if err != nil {
|
|
| 94 |
+ return nil, err |
|
| 95 |
+ } |
|
| 96 |
+ if err != nil {
|
|
| 97 |
+ return nil, errors.Wrapf(err, "could not parse url %q", host) |
|
| 98 |
+ } |
|
| 99 |
+ req, err := http.NewRequest("GET", endpoint, nil)
|
|
| 100 |
+ if err != nil {
|
|
| 101 |
+ return nil, fmt.Errorf("could not create new request: %v", err)
|
|
| 102 |
+ } |
|
| 103 |
+ |
|
| 104 |
+ req.URL.Scheme = "http" |
|
| 105 |
+ req.URL.Host = addr |
|
| 106 |
+ |
|
| 107 |
+ for _, config := range modifiers {
|
|
| 108 |
+ if err := config(req); err != nil {
|
|
| 109 |
+ return nil, err |
|
| 110 |
+ } |
|
| 111 |
+ } |
|
| 112 |
+ return req, nil |
|
| 113 |
+} |
|
| 114 |
+ |
|
| 115 |
+// NewClient creates an http client for the specific host |
|
| 116 |
+func NewClient(host string) (*http.Client, error) {
|
|
| 117 |
+ // FIXME(vdemeester) 10*time.Second timeout of SockRequest… ? |
|
| 118 |
+ proto, addr, _, err := dclient.ParseHost(host) |
|
| 119 |
+ if err != nil {
|
|
| 120 |
+ return nil, err |
|
| 121 |
+ } |
|
| 122 |
+ transport := new(http.Transport) |
|
| 123 |
+ if proto == "tcp" && os.Getenv("DOCKER_TLS_VERIFY") != "" {
|
|
| 124 |
+ // Setup the socket TLS configuration. |
|
| 125 |
+ tlsConfig, err := getTLSConfig() |
|
| 126 |
+ if err != nil {
|
|
| 127 |
+ return nil, err |
|
| 128 |
+ } |
|
| 129 |
+ transport = &http.Transport{TLSClientConfig: tlsConfig}
|
|
| 130 |
+ } |
|
| 131 |
+ err = sockets.ConfigureTransport(transport, proto, addr) |
|
| 132 |
+ return &http.Client{
|
|
| 133 |
+ Transport: transport, |
|
| 134 |
+ }, err |
|
| 135 |
+} |
|
| 136 |
+ |
|
| 137 |
+// FIXME(vdemeester) httputil.ClientConn is deprecated, use http.Client instead (closer to actual client) |
|
| 138 |
+// Deprecated: Use New instead of NewRequestClient |
|
| 139 |
+// Deprecated: use request.Do (or Get, Delete, Post) instead |
|
| 140 |
+func newRequestClient(method, endpoint string, data io.Reader, ct, daemon string, modifiers ...func(*http.Request)) (*http.Request, *httputil.ClientConn, error) {
|
|
| 141 |
+ c, err := SockConn(time.Duration(10*time.Second), daemon) |
|
| 142 |
+ if err != nil {
|
|
| 143 |
+ return nil, nil, fmt.Errorf("could not dial docker daemon: %v", err)
|
|
| 144 |
+ } |
|
| 145 |
+ |
|
| 146 |
+ client := httputil.NewClientConn(c, nil) |
|
| 147 |
+ |
|
| 148 |
+ req, err := http.NewRequest(method, endpoint, data) |
|
| 149 |
+ if err != nil {
|
|
| 150 |
+ client.Close() |
|
| 151 |
+ return nil, nil, fmt.Errorf("could not create new request: %v", err)
|
|
| 152 |
+ } |
|
| 153 |
+ |
|
| 154 |
+ for _, opt := range modifiers {
|
|
| 155 |
+ opt(req) |
|
| 156 |
+ } |
|
| 157 |
+ |
|
| 158 |
+ if ct != "" {
|
|
| 159 |
+ req.Header.Set("Content-Type", ct)
|
|
| 160 |
+ } |
|
| 161 |
+ return req, client, nil |
|
| 162 |
+} |
|
| 163 |
+ |
|
| 164 |
+// SockRequest create a request against the specified host (with method, endpoint and other request modifier) and |
|
| 165 |
+// returns the status code, and the content as an byte slice |
|
| 166 |
+// Deprecated: use request.Do instead |
|
| 167 |
+func SockRequest(method, endpoint string, data interface{}, daemon string, modifiers ...func(*http.Request)) (int, []byte, error) {
|
|
| 168 |
+ jsonData := bytes.NewBuffer(nil) |
|
| 169 |
+ if err := json.NewEncoder(jsonData).Encode(data); err != nil {
|
|
| 170 |
+ return -1, nil, err |
|
| 171 |
+ } |
|
| 172 |
+ |
|
| 173 |
+ res, body, err := SockRequestRaw(method, endpoint, jsonData, "application/json", daemon, modifiers...) |
|
| 174 |
+ if err != nil {
|
|
| 175 |
+ return -1, nil, err |
|
| 176 |
+ } |
|
| 177 |
+ b, err := testutil.ReadBody(body) |
|
| 178 |
+ return res.StatusCode, b, err |
|
| 179 |
+} |
|
| 180 |
+ |
|
| 181 |
+// SockRequestRaw create a request against the specified host (with method, endpoint and other request modifier) and |
|
| 182 |
+// returns the http response, the output as a io.ReadCloser |
|
| 183 |
+// Deprecated: use request.Do (or Get, Delete, Post) instead |
|
| 184 |
+func SockRequestRaw(method, endpoint string, data io.Reader, ct, daemon string, modifiers ...func(*http.Request)) (*http.Response, io.ReadCloser, error) {
|
|
| 185 |
+ req, client, err := newRequestClient(method, endpoint, data, ct, daemon, modifiers...) |
|
| 186 |
+ if err != nil {
|
|
| 187 |
+ return nil, nil, err |
|
| 188 |
+ } |
|
| 189 |
+ |
|
| 190 |
+ resp, err := client.Do(req) |
|
| 191 |
+ body := ioutils.NewReadCloserWrapper(resp.Body, func() error {
|
|
| 192 |
+ defer resp.Body.Close() |
|
| 193 |
+ return client.Close() |
|
| 194 |
+ }) |
|
| 195 |
+ if err != nil {
|
|
| 196 |
+ client.Close() |
|
| 197 |
+ } |
|
| 198 |
+ |
|
| 199 |
+ return resp, body, err |
|
| 200 |
+} |
|
| 201 |
+ |
|
| 202 |
+// SockRequestHijack creates a connection to specified host (with method, contenttype, …) and returns a hijacked connection |
|
| 203 |
+// and the output as a `bufio.Reader` |
|
| 204 |
+func SockRequestHijack(method, endpoint string, data io.Reader, ct string, daemon string, modifiers ...func(*http.Request)) (net.Conn, *bufio.Reader, error) {
|
|
| 205 |
+ req, client, err := newRequestClient(method, endpoint, data, ct, daemon, modifiers...) |
|
| 206 |
+ if err != nil {
|
|
| 207 |
+ return nil, nil, err |
|
| 208 |
+ } |
|
| 209 |
+ |
|
| 210 |
+ client.Do(req) |
|
| 211 |
+ conn, br := client.Hijack() |
|
| 212 |
+ return conn, br, nil |
|
| 213 |
+} |
|
| 214 |
+ |
|
| 215 |
+// SockConn opens a connection on the specified socket |
|
| 216 |
+func SockConn(timeout time.Duration, daemon string) (net.Conn, error) {
|
|
| 217 |
+ daemonURL, err := url.Parse(daemon) |
|
| 218 |
+ if err != nil {
|
|
| 219 |
+ return nil, errors.Wrapf(err, "could not parse url %q", daemon) |
|
| 220 |
+ } |
|
| 221 |
+ |
|
| 222 |
+ var c net.Conn |
|
| 223 |
+ switch daemonURL.Scheme {
|
|
| 224 |
+ case "npipe": |
|
| 225 |
+ return npipeDial(daemonURL.Path, timeout) |
|
| 226 |
+ case "unix": |
|
| 227 |
+ return net.DialTimeout(daemonURL.Scheme, daemonURL.Path, timeout) |
|
| 228 |
+ case "tcp": |
|
| 229 |
+ if os.Getenv("DOCKER_TLS_VERIFY") != "" {
|
|
| 230 |
+ // Setup the socket TLS configuration. |
|
| 231 |
+ tlsConfig, err := getTLSConfig() |
|
| 232 |
+ if err != nil {
|
|
| 233 |
+ return nil, err |
|
| 234 |
+ } |
|
| 235 |
+ dialer := &net.Dialer{Timeout: timeout}
|
|
| 236 |
+ return tls.DialWithDialer(dialer, daemonURL.Scheme, daemonURL.Host, tlsConfig) |
|
| 237 |
+ } |
|
| 238 |
+ return net.DialTimeout(daemonURL.Scheme, daemonURL.Host, timeout) |
|
| 239 |
+ default: |
|
| 240 |
+ return c, errors.Errorf("unknown scheme %v (%s)", daemonURL.Scheme, daemon)
|
|
| 241 |
+ } |
|
| 242 |
+} |
|
| 243 |
+ |
|
| 244 |
+func getTLSConfig() (*tls.Config, error) {
|
|
| 245 |
+ dockerCertPath := os.Getenv("DOCKER_CERT_PATH")
|
|
| 246 |
+ |
|
| 247 |
+ if dockerCertPath == "" {
|
|
| 248 |
+ return nil, errors.New("DOCKER_TLS_VERIFY specified, but no DOCKER_CERT_PATH environment variable")
|
|
| 249 |
+ } |
|
| 250 |
+ |
|
| 251 |
+ option := &tlsconfig.Options{
|
|
| 252 |
+ CAFile: filepath.Join(dockerCertPath, "ca.pem"), |
|
| 253 |
+ CertFile: filepath.Join(dockerCertPath, "cert.pem"), |
|
| 254 |
+ KeyFile: filepath.Join(dockerCertPath, "key.pem"), |
|
| 255 |
+ } |
|
| 256 |
+ tlsConfig, err := tlsconfig.Client(*option) |
|
| 257 |
+ if err != nil {
|
|
| 258 |
+ return nil, err |
|
| 259 |
+ } |
|
| 260 |
+ |
|
| 261 |
+ return tlsConfig, nil |
|
| 262 |
+} |