client: remove transport package
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestCheckpointCreateError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
err := client.CheckpointCreate(context.Background(), "nothing", types.CheckpointCreateOptions{
|
| 21 | 21 |
CheckpointID: "noting", |
| ... | ... |
@@ -33,7 +33,7 @@ func TestCheckpointCreate(t *testing.T) {
|
| 33 | 33 |
expectedURL := "/containers/container_id/checkpoints" |
| 34 | 34 |
|
| 35 | 35 |
client := &Client{
|
| 36 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 36 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 37 | 37 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 38 | 38 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 39 | 39 |
} |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
|
| 14 | 14 |
func TestCheckpointDeleteError(t *testing.T) {
|
| 15 | 15 |
client := &Client{
|
| 16 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 16 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 17 | 17 |
} |
| 18 | 18 |
|
| 19 | 19 |
err := client.CheckpointDelete(context.Background(), "container_id", "checkpoint_id") |
| ... | ... |
@@ -26,7 +26,7 @@ func TestCheckpointDelete(t *testing.T) {
|
| 26 | 26 |
expectedURL := "/containers/container_id/checkpoints/checkpoint_id" |
| 27 | 27 |
|
| 28 | 28 |
client := &Client{
|
| 29 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 29 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 30 | 30 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 31 | 31 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 32 | 32 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestCheckpointListError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
_, err := client.CheckpointList(context.Background(), "container_id") |
| ... | ... |
@@ -28,7 +28,7 @@ func TestCheckpointList(t *testing.T) {
|
| 28 | 28 |
expectedURL := "/containers/container_id/checkpoints" |
| 29 | 29 |
|
| 30 | 30 |
client := &Client{
|
| 31 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 31 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 32 | 32 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 33 | 33 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 34 | 34 |
} |
| ... | ... |
@@ -8,7 +8,7 @@ import ( |
| 8 | 8 |
"path/filepath" |
| 9 | 9 |
"strings" |
| 10 | 10 |
|
| 11 |
- "github.com/docker/docker/client/transport" |
|
| 11 |
+ "github.com/docker/go-connections/sockets" |
|
| 12 | 12 |
"github.com/docker/go-connections/tlsconfig" |
| 13 | 13 |
) |
| 14 | 14 |
|
| ... | ... |
@@ -26,8 +26,8 @@ type Client struct {
|
| 26 | 26 |
addr string |
| 27 | 27 |
// basePath holds the path to prepend to the requests. |
| 28 | 28 |
basePath string |
| 29 |
- // transport is the interface to send request with, it implements transport.Client. |
|
| 30 |
- transport transport.Client |
|
| 29 |
+ // client used to send and receive http requests. |
|
| 30 |
+ client *http.Client |
|
| 31 | 31 |
// version of the server to talk to. |
| 32 | 32 |
version string |
| 33 | 33 |
// custom http headers configured by users. |
| ... | ... |
@@ -86,9 +86,15 @@ func NewClient(host string, version string, client *http.Client, httpHeaders map |
| 86 | 86 |
return nil, err |
| 87 | 87 |
} |
| 88 | 88 |
|
| 89 |
- transport, err := transport.NewTransportWithHTTP(proto, addr, client) |
|
| 90 |
- if err != nil {
|
|
| 91 |
- return nil, err |
|
| 89 |
+ if client == nil {
|
|
| 90 |
+ client = &http.Client{}
|
|
| 91 |
+ } |
|
| 92 |
+ |
|
| 93 |
+ if client.Transport == nil {
|
|
| 94 |
+ // setup the transport, if not already present |
|
| 95 |
+ transport := new(http.Transport) |
|
| 96 |
+ sockets.ConfigureTransport(transport, proto, addr) |
|
| 97 |
+ client.Transport = transport |
|
| 92 | 98 |
} |
| 93 | 99 |
|
| 94 | 100 |
return &Client{
|
| ... | ... |
@@ -96,7 +102,7 @@ func NewClient(host string, version string, client *http.Client, httpHeaders map |
| 96 | 96 |
proto: proto, |
| 97 | 97 |
addr: addr, |
| 98 | 98 |
basePath: basePath, |
| 99 |
- transport: transport, |
|
| 99 |
+ client: client, |
|
| 100 | 100 |
version: version, |
| 101 | 101 |
customHTTPHeaders: httpHeaders, |
| 102 | 102 |
}, nil |
| ... | ... |
@@ -2,50 +2,19 @@ package client |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"bytes" |
| 5 |
- "crypto/tls" |
|
| 6 | 5 |
"encoding/json" |
| 7 | 6 |
"io/ioutil" |
| 8 | 7 |
"net/http" |
| 9 | 8 |
|
| 10 | 9 |
"github.com/docker/docker/api/types" |
| 11 |
- "github.com/docker/docker/client/transport" |
|
| 12 | 10 |
) |
| 13 | 11 |
|
| 14 |
-type mockClient struct {
|
|
| 15 |
- do func(*http.Request) (*http.Response, error) |
|
| 16 |
-} |
|
| 17 |
- |
|
| 18 |
-// TLSConfig returns the TLS configuration. |
|
| 19 |
-func (m *mockClient) TLSConfig() *tls.Config {
|
|
| 20 |
- return &tls.Config{}
|
|
| 21 |
-} |
|
| 22 |
- |
|
| 23 |
-// Scheme returns protocol scheme to use. |
|
| 24 |
-func (m *mockClient) Scheme() string {
|
|
| 25 |
- return "http" |
|
| 26 |
-} |
|
| 27 |
- |
|
| 28 |
-// Secure returns true if there is a TLS configuration. |
|
| 29 |
-func (m *mockClient) Secure() bool {
|
|
| 30 |
- return false |
|
| 31 |
-} |
|
| 32 |
- |
|
| 33 |
-// NewMockClient returns a mocked client that runs the function supplied as `client.Do` call |
|
| 34 |
-func newMockClient(tlsConfig *tls.Config, doer func(*http.Request) (*http.Response, error)) transport.Client {
|
|
| 35 |
- if tlsConfig != nil {
|
|
| 36 |
- panic("this actually gets set!")
|
|
| 37 |
- } |
|
| 38 |
- |
|
| 39 |
- return &mockClient{
|
|
| 40 |
- do: doer, |
|
| 12 |
+func newMockClient(doer func(*http.Request) (*http.Response, error)) *http.Client {
|
|
| 13 |
+ return &http.Client{
|
|
| 14 |
+ Transport: transportFunc(doer), |
|
| 41 | 15 |
} |
| 42 | 16 |
} |
| 43 | 17 |
|
| 44 |
-// Do executes the supplied function for the mock. |
|
| 45 |
-func (m mockClient) Do(req *http.Request) (*http.Response, error) {
|
|
| 46 |
- return m.do(req) |
|
| 47 |
-} |
|
| 48 |
- |
|
| 49 | 18 |
func errorMock(statusCode int, message string) func(req *http.Request) (*http.Response, error) {
|
| 50 | 19 |
return func(req *http.Request) (*http.Response, error) {
|
| 51 | 20 |
header := http.Header{}
|
| ... | ... |
@@ -173,7 +173,7 @@ func TestParseHost(t *testing.T) {
|
| 173 | 173 |
|
| 174 | 174 |
func TestUpdateClientVersion(t *testing.T) {
|
| 175 | 175 |
client := &Client{
|
| 176 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 176 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 177 | 177 |
splitQuery := strings.Split(req.URL.Path, "/") |
| 178 | 178 |
queryVersion := splitQuery[1] |
| 179 | 179 |
b, err := json.Marshal(types.Version{
|
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestContainerCommitError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
_, err := client.ContainerCommit(context.Background(), "nothing", types.ContainerCommitOptions{})
|
| 21 | 21 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -34,7 +34,7 @@ func TestContainerCommit(t *testing.T) {
|
| 34 | 34 |
expectedChanges := []string{"change1", "change2"}
|
| 35 | 35 |
|
| 36 | 36 |
client := &Client{
|
| 37 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 37 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 38 | 38 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 39 | 39 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 40 | 40 |
} |
| ... | ... |
@@ -17,7 +17,7 @@ import ( |
| 17 | 17 |
|
| 18 | 18 |
func TestContainerStatPathError(t *testing.T) {
|
| 19 | 19 |
client := &Client{
|
| 20 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 20 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 21 | 21 |
} |
| 22 | 22 |
_, err := client.ContainerStatPath(context.Background(), "container_id", "path") |
| 23 | 23 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -27,7 +27,7 @@ func TestContainerStatPathError(t *testing.T) {
|
| 27 | 27 |
|
| 28 | 28 |
func TestContainerStatPathNoHeaderError(t *testing.T) {
|
| 29 | 29 |
client := &Client{
|
| 30 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 30 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 31 | 31 |
return &http.Response{
|
| 32 | 32 |
StatusCode: http.StatusOK, |
| 33 | 33 |
Body: ioutil.NopCloser(bytes.NewReader([]byte(""))),
|
| ... | ... |
@@ -44,7 +44,7 @@ func TestContainerStatPath(t *testing.T) {
|
| 44 | 44 |
expectedURL := "/containers/container_id/archive" |
| 45 | 45 |
expectedPath := "path/to/file" |
| 46 | 46 |
client := &Client{
|
| 47 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 47 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 48 | 48 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 49 | 49 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 50 | 50 |
} |
| ... | ... |
@@ -87,7 +87,7 @@ func TestContainerStatPath(t *testing.T) {
|
| 87 | 87 |
|
| 88 | 88 |
func TestCopyToContainerError(t *testing.T) {
|
| 89 | 89 |
client := &Client{
|
| 90 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 90 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 91 | 91 |
} |
| 92 | 92 |
err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), types.CopyToContainerOptions{})
|
| 93 | 93 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -97,7 +97,7 @@ func TestCopyToContainerError(t *testing.T) {
|
| 97 | 97 |
|
| 98 | 98 |
func TestCopyToContainerNotStatusOKError(t *testing.T) {
|
| 99 | 99 |
client := &Client{
|
| 100 |
- transport: newMockClient(nil, errorMock(http.StatusNoContent, "No content")), |
|
| 100 |
+ client: newMockClient(errorMock(http.StatusNoContent, "No content")), |
|
| 101 | 101 |
} |
| 102 | 102 |
err := client.CopyToContainer(context.Background(), "container_id", "path/to/file", bytes.NewReader([]byte("")), types.CopyToContainerOptions{})
|
| 103 | 103 |
if err == nil || err.Error() != "unexpected status code from daemon: 204" {
|
| ... | ... |
@@ -109,7 +109,7 @@ func TestCopyToContainer(t *testing.T) {
|
| 109 | 109 |
expectedURL := "/containers/container_id/archive" |
| 110 | 110 |
expectedPath := "path/to/file" |
| 111 | 111 |
client := &Client{
|
| 112 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 112 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 113 | 113 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 114 | 114 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 115 | 115 |
} |
| ... | ... |
@@ -153,7 +153,7 @@ func TestCopyToContainer(t *testing.T) {
|
| 153 | 153 |
|
| 154 | 154 |
func TestCopyFromContainerError(t *testing.T) {
|
| 155 | 155 |
client := &Client{
|
| 156 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 156 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 157 | 157 |
} |
| 158 | 158 |
_, _, err := client.CopyFromContainer(context.Background(), "container_id", "path/to/file") |
| 159 | 159 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -163,7 +163,7 @@ func TestCopyFromContainerError(t *testing.T) {
|
| 163 | 163 |
|
| 164 | 164 |
func TestCopyFromContainerNotStatusOKError(t *testing.T) {
|
| 165 | 165 |
client := &Client{
|
| 166 |
- transport: newMockClient(nil, errorMock(http.StatusNoContent, "No content")), |
|
| 166 |
+ client: newMockClient(errorMock(http.StatusNoContent, "No content")), |
|
| 167 | 167 |
} |
| 168 | 168 |
_, _, err := client.CopyFromContainer(context.Background(), "container_id", "path/to/file") |
| 169 | 169 |
if err == nil || err.Error() != "unexpected status code from daemon: 204" {
|
| ... | ... |
@@ -173,7 +173,7 @@ func TestCopyFromContainerNotStatusOKError(t *testing.T) {
|
| 173 | 173 |
|
| 174 | 174 |
func TestCopyFromContainerNoHeaderError(t *testing.T) {
|
| 175 | 175 |
client := &Client{
|
| 176 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 176 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 177 | 177 |
return &http.Response{
|
| 178 | 178 |
StatusCode: http.StatusOK, |
| 179 | 179 |
Body: ioutil.NopCloser(bytes.NewReader([]byte(""))),
|
| ... | ... |
@@ -190,7 +190,7 @@ func TestCopyFromContainer(t *testing.T) {
|
| 190 | 190 |
expectedURL := "/containers/container_id/archive" |
| 191 | 191 |
expectedPath := "path/to/file" |
| 192 | 192 |
client := &Client{
|
| 193 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 193 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 194 | 194 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 195 | 195 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 196 | 196 |
} |
| ... | ... |
@@ -16,7 +16,7 @@ import ( |
| 16 | 16 |
|
| 17 | 17 |
func TestContainerCreateError(t *testing.T) {
|
| 18 | 18 |
client := &Client{
|
| 19 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 20 | 20 |
} |
| 21 | 21 |
_, err := client.ContainerCreate(context.Background(), nil, nil, nil, "nothing") |
| 22 | 22 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -25,7 +25,7 @@ func TestContainerCreateError(t *testing.T) {
|
| 25 | 25 |
|
| 26 | 26 |
// 404 doesn't automagitally means an unknown image |
| 27 | 27 |
client = &Client{
|
| 28 |
- transport: newMockClient(nil, errorMock(http.StatusNotFound, "Server error")), |
|
| 28 |
+ client: newMockClient(errorMock(http.StatusNotFound, "Server error")), |
|
| 29 | 29 |
} |
| 30 | 30 |
_, err = client.ContainerCreate(context.Background(), nil, nil, nil, "nothing") |
| 31 | 31 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -35,7 +35,7 @@ func TestContainerCreateError(t *testing.T) {
|
| 35 | 35 |
|
| 36 | 36 |
func TestContainerCreateImageNotFound(t *testing.T) {
|
| 37 | 37 |
client := &Client{
|
| 38 |
- transport: newMockClient(nil, errorMock(http.StatusNotFound, "No such image")), |
|
| 38 |
+ client: newMockClient(errorMock(http.StatusNotFound, "No such image")), |
|
| 39 | 39 |
} |
| 40 | 40 |
_, err := client.ContainerCreate(context.Background(), &container.Config{Image: "unknown_image"}, nil, nil, "unknown")
|
| 41 | 41 |
if err == nil || !IsErrImageNotFound(err) {
|
| ... | ... |
@@ -46,7 +46,7 @@ func TestContainerCreateImageNotFound(t *testing.T) {
|
| 46 | 46 |
func TestContainerCreateWithName(t *testing.T) {
|
| 47 | 47 |
expectedURL := "/containers/create" |
| 48 | 48 |
client := &Client{
|
| 49 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 49 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 50 | 50 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 51 | 51 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 52 | 52 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestContainerDiffError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
_, err := client.ContainerDiff(context.Background(), "nothing") |
| 21 | 21 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -27,7 +27,7 @@ func TestContainerDiffError(t *testing.T) {
|
| 27 | 27 |
func TestContainerDiff(t *testing.T) {
|
| 28 | 28 |
expectedURL := "/containers/container_id/changes" |
| 29 | 29 |
client := &Client{
|
| 30 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 30 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 31 | 31 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 32 | 32 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 33 | 33 |
} |
| ... | ... |
@@ -16,7 +16,7 @@ import ( |
| 16 | 16 |
|
| 17 | 17 |
func TestContainerExecCreateError(t *testing.T) {
|
| 18 | 18 |
client := &Client{
|
| 19 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 20 | 20 |
} |
| 21 | 21 |
_, err := client.ContainerExecCreate(context.Background(), "container_id", types.ExecConfig{})
|
| 22 | 22 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -27,7 +27,7 @@ func TestContainerExecCreateError(t *testing.T) {
|
| 27 | 27 |
func TestContainerExecCreate(t *testing.T) {
|
| 28 | 28 |
expectedURL := "/containers/container_id/exec" |
| 29 | 29 |
client := &Client{
|
| 30 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 30 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 31 | 31 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 32 | 32 |
return nil, fmt.Errorf("expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 33 | 33 |
} |
| ... | ... |
@@ -71,7 +71,7 @@ func TestContainerExecCreate(t *testing.T) {
|
| 71 | 71 |
|
| 72 | 72 |
func TestContainerExecStartError(t *testing.T) {
|
| 73 | 73 |
client := &Client{
|
| 74 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 74 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 75 | 75 |
} |
| 76 | 76 |
err := client.ContainerExecStart(context.Background(), "nothing", types.ExecStartCheck{})
|
| 77 | 77 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -82,7 +82,7 @@ func TestContainerExecStartError(t *testing.T) {
|
| 82 | 82 |
func TestContainerExecStart(t *testing.T) {
|
| 83 | 83 |
expectedURL := "/exec/exec_id/start" |
| 84 | 84 |
client := &Client{
|
| 85 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 85 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 86 | 86 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 87 | 87 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 88 | 88 |
} |
| ... | ... |
@@ -115,7 +115,7 @@ func TestContainerExecStart(t *testing.T) {
|
| 115 | 115 |
|
| 116 | 116 |
func TestContainerExecInspectError(t *testing.T) {
|
| 117 | 117 |
client := &Client{
|
| 118 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 118 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 119 | 119 |
} |
| 120 | 120 |
_, err := client.ContainerExecInspect(context.Background(), "nothing") |
| 121 | 121 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -126,7 +126,7 @@ func TestContainerExecInspectError(t *testing.T) {
|
| 126 | 126 |
func TestContainerExecInspect(t *testing.T) {
|
| 127 | 127 |
expectedURL := "/exec/exec_id/json" |
| 128 | 128 |
client := &Client{
|
| 129 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 129 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 130 | 130 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 131 | 131 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 132 | 132 |
} |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
|
| 14 | 14 |
func TestContainerExportError(t *testing.T) {
|
| 15 | 15 |
client := &Client{
|
| 16 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 16 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 17 | 17 |
} |
| 18 | 18 |
_, err := client.ContainerExport(context.Background(), "nothing") |
| 19 | 19 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -24,7 +24,7 @@ func TestContainerExportError(t *testing.T) {
|
| 24 | 24 |
func TestContainerExport(t *testing.T) {
|
| 25 | 25 |
expectedURL := "/containers/container_id/export" |
| 26 | 26 |
client := &Client{
|
| 27 |
- transport: newMockClient(nil, func(r *http.Request) (*http.Response, error) {
|
|
| 27 |
+ client: newMockClient(func(r *http.Request) (*http.Response, error) {
|
|
| 28 | 28 |
if !strings.HasPrefix(r.URL.Path, expectedURL) {
|
| 29 | 29 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL)
|
| 30 | 30 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestContainerInspectError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
_, err := client.ContainerInspect(context.Background(), "nothing") |
| ... | ... |
@@ -26,7 +26,7 @@ func TestContainerInspectError(t *testing.T) {
|
| 26 | 26 |
|
| 27 | 27 |
func TestContainerInspectContainerNotFound(t *testing.T) {
|
| 28 | 28 |
client := &Client{
|
| 29 |
- transport: newMockClient(nil, errorMock(http.StatusNotFound, "Server error")), |
|
| 29 |
+ client: newMockClient(errorMock(http.StatusNotFound, "Server error")), |
|
| 30 | 30 |
} |
| 31 | 31 |
|
| 32 | 32 |
_, err := client.ContainerInspect(context.Background(), "unknown") |
| ... | ... |
@@ -38,7 +38,7 @@ func TestContainerInspectContainerNotFound(t *testing.T) {
|
| 38 | 38 |
func TestContainerInspect(t *testing.T) {
|
| 39 | 39 |
expectedURL := "/containers/container_id/json" |
| 40 | 40 |
client := &Client{
|
| 41 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 41 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 42 | 42 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 43 | 43 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 44 | 44 |
} |
| ... | ... |
@@ -76,7 +76,7 @@ func TestContainerInspect(t *testing.T) {
|
| 76 | 76 |
|
| 77 | 77 |
func TestContainerInspectNode(t *testing.T) {
|
| 78 | 78 |
client := &Client{
|
| 79 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 79 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 80 | 80 |
content, err := json.Marshal(types.ContainerJSON{
|
| 81 | 81 |
ContainerJSONBase: &types.ContainerJSONBase{
|
| 82 | 82 |
ID: "container_id", |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
|
| 14 | 14 |
func TestContainerKillError(t *testing.T) {
|
| 15 | 15 |
client := &Client{
|
| 16 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 16 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 17 | 17 |
} |
| 18 | 18 |
err := client.ContainerKill(context.Background(), "nothing", "SIGKILL") |
| 19 | 19 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -24,7 +24,7 @@ func TestContainerKillError(t *testing.T) {
|
| 24 | 24 |
func TestContainerKill(t *testing.T) {
|
| 25 | 25 |
expectedURL := "/containers/container_id/kill" |
| 26 | 26 |
client := &Client{
|
| 27 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 27 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 28 | 28 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 29 | 29 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 30 | 30 |
} |
| ... | ... |
@@ -16,7 +16,7 @@ import ( |
| 16 | 16 |
|
| 17 | 17 |
func TestContainerListError(t *testing.T) {
|
| 18 | 18 |
client := &Client{
|
| 19 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 20 | 20 |
} |
| 21 | 21 |
_, err := client.ContainerList(context.Background(), types.ContainerListOptions{})
|
| 22 | 22 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -28,7 +28,7 @@ func TestContainerList(t *testing.T) {
|
| 28 | 28 |
expectedURL := "/containers/json" |
| 29 | 29 |
expectedFilters := `{"before":{"container":true},"label":{"label1":true,"label2":true}}`
|
| 30 | 30 |
client := &Client{
|
| 31 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 31 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 32 | 32 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 33 | 33 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 34 | 34 |
} |
| ... | ... |
@@ -19,7 +19,7 @@ import ( |
| 19 | 19 |
|
| 20 | 20 |
func TestContainerLogsError(t *testing.T) {
|
| 21 | 21 |
client := &Client{
|
| 22 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 22 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 23 | 23 |
} |
| 24 | 24 |
_, err := client.ContainerLogs(context.Background(), "container_id", types.ContainerLogsOptions{})
|
| 25 | 25 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -83,7 +83,7 @@ func TestContainerLogs(t *testing.T) {
|
| 83 | 83 |
} |
| 84 | 84 |
for _, logCase := range cases {
|
| 85 | 85 |
client := &Client{
|
| 86 |
- transport: newMockClient(nil, func(r *http.Request) (*http.Response, error) {
|
|
| 86 |
+ client: newMockClient(func(r *http.Request) (*http.Response, error) {
|
|
| 87 | 87 |
if !strings.HasPrefix(r.URL.Path, expectedURL) {
|
| 88 | 88 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL)
|
| 89 | 89 |
} |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
|
| 14 | 14 |
func TestContainerPauseError(t *testing.T) {
|
| 15 | 15 |
client := &Client{
|
| 16 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 16 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 17 | 17 |
} |
| 18 | 18 |
err := client.ContainerPause(context.Background(), "nothing") |
| 19 | 19 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -24,7 +24,7 @@ func TestContainerPauseError(t *testing.T) {
|
| 24 | 24 |
func TestContainerPause(t *testing.T) {
|
| 25 | 25 |
expectedURL := "/containers/container_id/pause" |
| 26 | 26 |
client := &Client{
|
| 27 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 27 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 28 | 28 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 29 | 29 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 30 | 30 |
} |
| ... | ... |
@@ -14,7 +14,7 @@ import ( |
| 14 | 14 |
|
| 15 | 15 |
func TestContainerRemoveError(t *testing.T) {
|
| 16 | 16 |
client := &Client{
|
| 17 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 17 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 | 18 |
} |
| 19 | 19 |
err := client.ContainerRemove(context.Background(), "container_id", types.ContainerRemoveOptions{})
|
| 20 | 20 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -25,7 +25,7 @@ func TestContainerRemoveError(t *testing.T) {
|
| 25 | 25 |
func TestContainerRemove(t *testing.T) {
|
| 26 | 26 |
expectedURL := "/containers/container_id" |
| 27 | 27 |
client := &Client{
|
| 28 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 28 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 29 | 29 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 30 | 30 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 31 | 31 |
} |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
|
| 14 | 14 |
func TestContainerRenameError(t *testing.T) {
|
| 15 | 15 |
client := &Client{
|
| 16 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 16 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 17 | 17 |
} |
| 18 | 18 |
err := client.ContainerRename(context.Background(), "nothing", "newNothing") |
| 19 | 19 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -24,7 +24,7 @@ func TestContainerRenameError(t *testing.T) {
|
| 24 | 24 |
func TestContainerRename(t *testing.T) {
|
| 25 | 25 |
expectedURL := "/containers/container_id/rename" |
| 26 | 26 |
client := &Client{
|
| 27 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 27 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 28 | 28 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 29 | 29 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 30 | 30 |
} |
| ... | ... |
@@ -14,7 +14,7 @@ import ( |
| 14 | 14 |
|
| 15 | 15 |
func TestContainerResizeError(t *testing.T) {
|
| 16 | 16 |
client := &Client{
|
| 17 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 17 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 | 18 |
} |
| 19 | 19 |
err := client.ContainerResize(context.Background(), "container_id", types.ResizeOptions{})
|
| 20 | 20 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -24,7 +24,7 @@ func TestContainerResizeError(t *testing.T) {
|
| 24 | 24 |
|
| 25 | 25 |
func TestContainerExecResizeError(t *testing.T) {
|
| 26 | 26 |
client := &Client{
|
| 27 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 27 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 28 | 28 |
} |
| 29 | 29 |
err := client.ContainerExecResize(context.Background(), "exec_id", types.ResizeOptions{})
|
| 30 | 30 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -34,7 +34,7 @@ func TestContainerExecResizeError(t *testing.T) {
|
| 34 | 34 |
|
| 35 | 35 |
func TestContainerResize(t *testing.T) {
|
| 36 | 36 |
client := &Client{
|
| 37 |
- transport: newMockClient(nil, resizeTransport("/containers/container_id/resize")),
|
|
| 37 |
+ client: newMockClient(resizeTransport("/containers/container_id/resize")),
|
|
| 38 | 38 |
} |
| 39 | 39 |
|
| 40 | 40 |
err := client.ContainerResize(context.Background(), "container_id", types.ResizeOptions{
|
| ... | ... |
@@ -48,7 +48,7 @@ func TestContainerResize(t *testing.T) {
|
| 48 | 48 |
|
| 49 | 49 |
func TestContainerExecResize(t *testing.T) {
|
| 50 | 50 |
client := &Client{
|
| 51 |
- transport: newMockClient(nil, resizeTransport("/exec/exec_id/resize")),
|
|
| 51 |
+ client: newMockClient(resizeTransport("/exec/exec_id/resize")),
|
|
| 52 | 52 |
} |
| 53 | 53 |
|
| 54 | 54 |
err := client.ContainerExecResize(context.Background(), "exec_id", types.ResizeOptions{
|
| ... | ... |
@@ -14,7 +14,7 @@ import ( |
| 14 | 14 |
|
| 15 | 15 |
func TestContainerRestartError(t *testing.T) {
|
| 16 | 16 |
client := &Client{
|
| 17 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 17 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 | 18 |
} |
| 19 | 19 |
timeout := 0 * time.Second |
| 20 | 20 |
err := client.ContainerRestart(context.Background(), "nothing", &timeout) |
| ... | ... |
@@ -26,7 +26,7 @@ func TestContainerRestartError(t *testing.T) {
|
| 26 | 26 |
func TestContainerRestart(t *testing.T) {
|
| 27 | 27 |
expectedURL := "/containers/container_id/restart" |
| 28 | 28 |
client := &Client{
|
| 29 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 29 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 30 | 30 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 31 | 31 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 32 | 32 |
} |
| ... | ... |
@@ -16,7 +16,7 @@ import ( |
| 16 | 16 |
|
| 17 | 17 |
func TestContainerStartError(t *testing.T) {
|
| 18 | 18 |
client := &Client{
|
| 19 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 20 | 20 |
} |
| 21 | 21 |
err := client.ContainerStart(context.Background(), "nothing", types.ContainerStartOptions{})
|
| 22 | 22 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -27,7 +27,7 @@ func TestContainerStartError(t *testing.T) {
|
| 27 | 27 |
func TestContainerStart(t *testing.T) {
|
| 28 | 28 |
expectedURL := "/containers/container_id/start" |
| 29 | 29 |
client := &Client{
|
| 30 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 30 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 31 | 31 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 32 | 32 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 33 | 33 |
} |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
|
| 14 | 14 |
func TestContainerStatsError(t *testing.T) {
|
| 15 | 15 |
client := &Client{
|
| 16 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 16 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 17 | 17 |
} |
| 18 | 18 |
_, err := client.ContainerStats(context.Background(), "nothing", false) |
| 19 | 19 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -37,7 +37,7 @@ func TestContainerStats(t *testing.T) {
|
| 37 | 37 |
} |
| 38 | 38 |
for _, c := range cases {
|
| 39 | 39 |
client := &Client{
|
| 40 |
- transport: newMockClient(nil, func(r *http.Request) (*http.Response, error) {
|
|
| 40 |
+ client: newMockClient(func(r *http.Request) (*http.Response, error) {
|
|
| 41 | 41 |
if !strings.HasPrefix(r.URL.Path, expectedURL) {
|
| 42 | 42 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL)
|
| 43 | 43 |
} |
| ... | ... |
@@ -14,7 +14,7 @@ import ( |
| 14 | 14 |
|
| 15 | 15 |
func TestContainerStopError(t *testing.T) {
|
| 16 | 16 |
client := &Client{
|
| 17 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 17 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 | 18 |
} |
| 19 | 19 |
timeout := 0 * time.Second |
| 20 | 20 |
err := client.ContainerStop(context.Background(), "nothing", &timeout) |
| ... | ... |
@@ -26,7 +26,7 @@ func TestContainerStopError(t *testing.T) {
|
| 26 | 26 |
func TestContainerStop(t *testing.T) {
|
| 27 | 27 |
expectedURL := "/containers/container_id/stop" |
| 28 | 28 |
client := &Client{
|
| 29 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 29 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 30 | 30 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 31 | 31 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 32 | 32 |
} |
| ... | ... |
@@ -16,7 +16,7 @@ import ( |
| 16 | 16 |
|
| 17 | 17 |
func TestContainerTopError(t *testing.T) {
|
| 18 | 18 |
client := &Client{
|
| 19 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 20 | 20 |
} |
| 21 | 21 |
_, err := client.ContainerTop(context.Background(), "nothing", []string{})
|
| 22 | 22 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -33,7 +33,7 @@ func TestContainerTop(t *testing.T) {
|
| 33 | 33 |
expectedTitles := []string{"title1", "title2"}
|
| 34 | 34 |
|
| 35 | 35 |
client := &Client{
|
| 36 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 36 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 37 | 37 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 38 | 38 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 39 | 39 |
} |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
|
| 14 | 14 |
func TestContainerUnpauseError(t *testing.T) {
|
| 15 | 15 |
client := &Client{
|
| 16 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 16 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 17 | 17 |
} |
| 18 | 18 |
err := client.ContainerUnpause(context.Background(), "nothing") |
| 19 | 19 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -24,7 +24,7 @@ func TestContainerUnpauseError(t *testing.T) {
|
| 24 | 24 |
func TestContainerUnpause(t *testing.T) {
|
| 25 | 25 |
expectedURL := "/containers/container_id/unpause" |
| 26 | 26 |
client := &Client{
|
| 27 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 27 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 28 | 28 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 29 | 29 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 30 | 30 |
} |
| ... | ... |
@@ -16,7 +16,7 @@ import ( |
| 16 | 16 |
|
| 17 | 17 |
func TestContainerUpdateError(t *testing.T) {
|
| 18 | 18 |
client := &Client{
|
| 19 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 20 | 20 |
} |
| 21 | 21 |
_, err := client.ContainerUpdate(context.Background(), "nothing", container.UpdateConfig{})
|
| 22 | 22 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -28,7 +28,7 @@ func TestContainerUpdate(t *testing.T) {
|
| 28 | 28 |
expectedURL := "/containers/container_id/update" |
| 29 | 29 |
|
| 30 | 30 |
client := &Client{
|
| 31 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 31 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 32 | 32 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 33 | 33 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 34 | 34 |
} |
| ... | ... |
@@ -18,7 +18,7 @@ import ( |
| 18 | 18 |
|
| 19 | 19 |
func TestContainerWaitError(t *testing.T) {
|
| 20 | 20 |
client := &Client{
|
| 21 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 21 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 22 | 22 |
} |
| 23 | 23 |
code, err := client.ContainerWait(context.Background(), "nothing") |
| 24 | 24 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -32,7 +32,7 @@ func TestContainerWaitError(t *testing.T) {
|
| 32 | 32 |
func TestContainerWait(t *testing.T) {
|
| 33 | 33 |
expectedURL := "/containers/container_id/wait" |
| 34 | 34 |
client := &Client{
|
| 35 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 35 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 36 | 36 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 37 | 37 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 38 | 38 |
} |
| ... | ... |
@@ -34,7 +34,7 @@ func TestEventsErrorInOptions(t *testing.T) {
|
| 34 | 34 |
} |
| 35 | 35 |
for _, e := range errorCases {
|
| 36 | 36 |
client := &Client{
|
| 37 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 37 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 38 | 38 |
} |
| 39 | 39 |
_, err := client.Events(context.Background(), e.options) |
| 40 | 40 |
if err == nil || !strings.Contains(err.Error(), e.expectedError) {
|
| ... | ... |
@@ -45,7 +45,7 @@ func TestEventsErrorInOptions(t *testing.T) {
|
| 45 | 45 |
|
| 46 | 46 |
func TestEventsErrorFromServer(t *testing.T) {
|
| 47 | 47 |
client := &Client{
|
| 48 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 48 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 49 | 49 |
} |
| 50 | 50 |
_, err := client.Events(context.Background(), types.EventsOptions{})
|
| 51 | 51 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -93,7 +93,7 @@ func TestEvents(t *testing.T) {
|
| 93 | 93 |
|
| 94 | 94 |
for _, eventsCase := range eventsCases {
|
| 95 | 95 |
client := &Client{
|
| 96 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 96 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 97 | 97 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 98 | 98 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 99 | 99 |
} |
| ... | ... |
@@ -11,7 +11,7 @@ import ( |
| 11 | 11 |
"time" |
| 12 | 12 |
|
| 13 | 13 |
"github.com/docker/docker/api/types" |
| 14 |
- "github.com/docker/docker/client/transport" |
|
| 14 |
+ "github.com/docker/docker/pkg/tlsconfig" |
|
| 15 | 15 |
"github.com/docker/go-connections/sockets" |
| 16 | 16 |
"golang.org/x/net/context" |
| 17 | 17 |
) |
| ... | ... |
@@ -47,7 +47,12 @@ func (cli *Client) postHijacked(ctx context.Context, path string, query url.Valu |
| 47 | 47 |
req.Header.Set("Connection", "Upgrade")
|
| 48 | 48 |
req.Header.Set("Upgrade", "tcp")
|
| 49 | 49 |
|
| 50 |
- conn, err := dial(cli.proto, cli.addr, cli.transport.TLSConfig()) |
|
| 50 |
+ tlsConfig, err := resolveTLSConfig(cli.client.Transport) |
|
| 51 |
+ if err != nil {
|
|
| 52 |
+ return types.HijackedResponse{}, err
|
|
| 53 |
+ } |
|
| 54 |
+ |
|
| 55 |
+ conn, err := dial(cli.proto, cli.addr, tlsConfig) |
|
| 51 | 56 |
if err != nil {
|
| 52 | 57 |
if strings.Contains(err.Error(), "connection refused") {
|
| 53 | 58 |
return types.HijackedResponse{}, fmt.Errorf("Cannot connect to the Docker daemon. Is 'docker daemon' running on this host?")
|
| ... | ... |
@@ -136,7 +141,7 @@ func tlsDialWithDialer(dialer *net.Dialer, network, addr string, config *tls.Con |
| 136 | 136 |
// from the hostname we're connecting to. |
| 137 | 137 |
if config.ServerName == "" {
|
| 138 | 138 |
// Make a copy to avoid polluting argument or default. |
| 139 |
- config = transport.TLSConfigClone(config) |
|
| 139 |
+ config = tlsconfig.Clone(config) |
|
| 140 | 140 |
config.ServerName = hostname |
| 141 | 141 |
} |
| 142 | 142 |
|
| ... | ... |
@@ -18,7 +18,7 @@ import ( |
| 18 | 18 |
|
| 19 | 19 |
func TestImageBuildError(t *testing.T) {
|
| 20 | 20 |
client := &Client{
|
| 21 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 21 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 22 | 22 |
} |
| 23 | 23 |
_, err := client.ImageBuild(context.Background(), nil, types.ImageBuildOptions{})
|
| 24 | 24 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -157,7 +157,7 @@ func TestImageBuild(t *testing.T) {
|
| 157 | 157 |
for _, buildCase := range buildCases {
|
| 158 | 158 |
expectedURL := "/build" |
| 159 | 159 |
client := &Client{
|
| 160 |
- transport: newMockClient(nil, func(r *http.Request) (*http.Response, error) {
|
|
| 160 |
+ client: newMockClient(func(r *http.Request) (*http.Response, error) {
|
|
| 161 | 161 |
if !strings.HasPrefix(r.URL.Path, expectedURL) {
|
| 162 | 162 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL)
|
| 163 | 163 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestImageCreateError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
_, err := client.ImageCreate(context.Background(), "reference", types.ImageCreateOptions{})
|
| 21 | 21 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -30,7 +30,7 @@ func TestImageCreate(t *testing.T) {
|
| 30 | 30 |
expectedReference := fmt.Sprintf("%s@%s", expectedImage, expectedTag)
|
| 31 | 31 |
expectedRegistryAuth := "eyJodHRwczovL2luZGV4LmRvY2tlci5pby92MS8iOnsiYXV0aCI6ImRHOTBid289IiwiZW1haWwiOiJqb2huQGRvZS5jb20ifX0=" |
| 32 | 32 |
client := &Client{
|
| 33 |
- transport: newMockClient(nil, func(r *http.Request) (*http.Response, error) {
|
|
| 33 |
+ client: newMockClient(func(r *http.Request) (*http.Response, error) {
|
|
| 34 | 34 |
if !strings.HasPrefix(r.URL.Path, expectedURL) {
|
| 35 | 35 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL)
|
| 36 | 36 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestImageHistoryError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
_, err := client.ImageHistory(context.Background(), "nothing") |
| 21 | 21 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -26,7 +26,7 @@ func TestImageHistoryError(t *testing.T) {
|
| 26 | 26 |
func TestImageHistory(t *testing.T) {
|
| 27 | 27 |
expectedURL := "/images/image_id/history" |
| 28 | 28 |
client := &Client{
|
| 29 |
- transport: newMockClient(nil, func(r *http.Request) (*http.Response, error) {
|
|
| 29 |
+ client: newMockClient(func(r *http.Request) (*http.Response, error) {
|
|
| 30 | 30 |
if !strings.HasPrefix(r.URL.Path, expectedURL) {
|
| 31 | 31 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL)
|
| 32 | 32 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestImageImportError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
_, err := client.ImageImport(context.Background(), types.ImageImportSource{}, "image:tag", types.ImageImportOptions{})
|
| 21 | 21 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -26,7 +26,7 @@ func TestImageImportError(t *testing.T) {
|
| 26 | 26 |
func TestImageImport(t *testing.T) {
|
| 27 | 27 |
expectedURL := "/images/create" |
| 28 | 28 |
client := &Client{
|
| 29 |
- transport: newMockClient(nil, func(r *http.Request) (*http.Response, error) {
|
|
| 29 |
+ client: newMockClient(func(r *http.Request) (*http.Response, error) {
|
|
| 30 | 30 |
if !strings.HasPrefix(r.URL.Path, expectedURL) {
|
| 31 | 31 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL)
|
| 32 | 32 |
} |
| ... | ... |
@@ -16,7 +16,7 @@ import ( |
| 16 | 16 |
|
| 17 | 17 |
func TestImageInspectError(t *testing.T) {
|
| 18 | 18 |
client := &Client{
|
| 19 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 20 | 20 |
} |
| 21 | 21 |
|
| 22 | 22 |
_, _, err := client.ImageInspectWithRaw(context.Background(), "nothing") |
| ... | ... |
@@ -27,7 +27,7 @@ func TestImageInspectError(t *testing.T) {
|
| 27 | 27 |
|
| 28 | 28 |
func TestImageInspectImageNotFound(t *testing.T) {
|
| 29 | 29 |
client := &Client{
|
| 30 |
- transport: newMockClient(nil, errorMock(http.StatusNotFound, "Server error")), |
|
| 30 |
+ client: newMockClient(errorMock(http.StatusNotFound, "Server error")), |
|
| 31 | 31 |
} |
| 32 | 32 |
|
| 33 | 33 |
_, _, err := client.ImageInspectWithRaw(context.Background(), "unknown") |
| ... | ... |
@@ -40,7 +40,7 @@ func TestImageInspect(t *testing.T) {
|
| 40 | 40 |
expectedURL := "/images/image_id/json" |
| 41 | 41 |
expectedTags := []string{"tag1", "tag2"}
|
| 42 | 42 |
client := &Client{
|
| 43 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 43 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 44 | 44 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 45 | 45 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 46 | 46 |
} |
| ... | ... |
@@ -16,7 +16,7 @@ import ( |
| 16 | 16 |
|
| 17 | 17 |
func TestImageListError(t *testing.T) {
|
| 18 | 18 |
client := &Client{
|
| 19 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 20 | 20 |
} |
| 21 | 21 |
|
| 22 | 22 |
_, err := client.ImageList(context.Background(), types.ImageListOptions{})
|
| ... | ... |
@@ -82,7 +82,7 @@ func TestImageList(t *testing.T) {
|
| 82 | 82 |
} |
| 83 | 83 |
for _, listCase := range listCases {
|
| 84 | 84 |
client := &Client{
|
| 85 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 85 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 86 | 86 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 87 | 87 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 88 | 88 |
} |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
|
| 14 | 14 |
func TestImageLoadError(t *testing.T) {
|
| 15 | 15 |
client := &Client{
|
| 16 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 16 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 17 | 17 |
} |
| 18 | 18 |
|
| 19 | 19 |
_, err := client.ImageLoad(context.Background(), nil, true) |
| ... | ... |
@@ -51,7 +51,7 @@ func TestImageLoad(t *testing.T) {
|
| 51 | 51 |
} |
| 52 | 52 |
for _, loadCase := range loadCases {
|
| 53 | 53 |
client := &Client{
|
| 54 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 54 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 55 | 55 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 56 | 56 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 57 | 57 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestImagePullReferenceParseError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 18 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 19 | 19 |
return nil, nil |
| 20 | 20 |
}), |
| 21 | 21 |
} |
| ... | ... |
@@ -28,7 +28,7 @@ func TestImagePullReferenceParseError(t *testing.T) {
|
| 28 | 28 |
|
| 29 | 29 |
func TestImagePullAnyError(t *testing.T) {
|
| 30 | 30 |
client := &Client{
|
| 31 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 31 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 32 | 32 |
} |
| 33 | 33 |
_, err := client.ImagePull(context.Background(), "myimage", types.ImagePullOptions{})
|
| 34 | 34 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -38,7 +38,7 @@ func TestImagePullAnyError(t *testing.T) {
|
| 38 | 38 |
|
| 39 | 39 |
func TestImagePullStatusUnauthorizedError(t *testing.T) {
|
| 40 | 40 |
client := &Client{
|
| 41 |
- transport: newMockClient(nil, errorMock(http.StatusUnauthorized, "Unauthorized error")), |
|
| 41 |
+ client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), |
|
| 42 | 42 |
} |
| 43 | 43 |
_, err := client.ImagePull(context.Background(), "myimage", types.ImagePullOptions{})
|
| 44 | 44 |
if err == nil || err.Error() != "Error response from daemon: Unauthorized error" {
|
| ... | ... |
@@ -48,7 +48,7 @@ func TestImagePullStatusUnauthorizedError(t *testing.T) {
|
| 48 | 48 |
|
| 49 | 49 |
func TestImagePullWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) {
|
| 50 | 50 |
client := &Client{
|
| 51 |
- transport: newMockClient(nil, errorMock(http.StatusUnauthorized, "Unauthorized error")), |
|
| 51 |
+ client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), |
|
| 52 | 52 |
} |
| 53 | 53 |
privilegeFunc := func() (string, error) {
|
| 54 | 54 |
return "", fmt.Errorf("Error requesting privilege")
|
| ... | ... |
@@ -63,7 +63,7 @@ func TestImagePullWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) {
|
| 63 | 63 |
|
| 64 | 64 |
func TestImagePullWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing.T) {
|
| 65 | 65 |
client := &Client{
|
| 66 |
- transport: newMockClient(nil, errorMock(http.StatusUnauthorized, "Unauthorized error")), |
|
| 66 |
+ client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), |
|
| 67 | 67 |
} |
| 68 | 68 |
privilegeFunc := func() (string, error) {
|
| 69 | 69 |
return "a-auth-header", nil |
| ... | ... |
@@ -79,7 +79,7 @@ func TestImagePullWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing.T) |
| 79 | 79 |
func TestImagePullWithPrivilegedFuncNoError(t *testing.T) {
|
| 80 | 80 |
expectedURL := "/images/create" |
| 81 | 81 |
client := &Client{
|
| 82 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 82 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 83 | 83 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 84 | 84 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 85 | 85 |
} |
| ... | ... |
@@ -163,7 +163,7 @@ func TestImagePullWithoutErrors(t *testing.T) {
|
| 163 | 163 |
} |
| 164 | 164 |
for _, pullCase := range pullCases {
|
| 165 | 165 |
client := &Client{
|
| 166 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 166 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 167 | 167 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 168 | 168 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 169 | 169 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestImagePushReferenceError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 18 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 19 | 19 |
return nil, nil |
| 20 | 20 |
}), |
| 21 | 21 |
} |
| ... | ... |
@@ -33,7 +33,7 @@ func TestImagePushReferenceError(t *testing.T) {
|
| 33 | 33 |
|
| 34 | 34 |
func TestImagePushAnyError(t *testing.T) {
|
| 35 | 35 |
client := &Client{
|
| 36 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 36 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 37 | 37 |
} |
| 38 | 38 |
_, err := client.ImagePush(context.Background(), "myimage", types.ImagePushOptions{})
|
| 39 | 39 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -43,7 +43,7 @@ func TestImagePushAnyError(t *testing.T) {
|
| 43 | 43 |
|
| 44 | 44 |
func TestImagePushStatusUnauthorizedError(t *testing.T) {
|
| 45 | 45 |
client := &Client{
|
| 46 |
- transport: newMockClient(nil, errorMock(http.StatusUnauthorized, "Unauthorized error")), |
|
| 46 |
+ client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), |
|
| 47 | 47 |
} |
| 48 | 48 |
_, err := client.ImagePush(context.Background(), "myimage", types.ImagePushOptions{})
|
| 49 | 49 |
if err == nil || err.Error() != "Error response from daemon: Unauthorized error" {
|
| ... | ... |
@@ -53,7 +53,7 @@ func TestImagePushStatusUnauthorizedError(t *testing.T) {
|
| 53 | 53 |
|
| 54 | 54 |
func TestImagePushWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) {
|
| 55 | 55 |
client := &Client{
|
| 56 |
- transport: newMockClient(nil, errorMock(http.StatusUnauthorized, "Unauthorized error")), |
|
| 56 |
+ client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), |
|
| 57 | 57 |
} |
| 58 | 58 |
privilegeFunc := func() (string, error) {
|
| 59 | 59 |
return "", fmt.Errorf("Error requesting privilege")
|
| ... | ... |
@@ -68,7 +68,7 @@ func TestImagePushWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) {
|
| 68 | 68 |
|
| 69 | 69 |
func TestImagePushWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing.T) {
|
| 70 | 70 |
client := &Client{
|
| 71 |
- transport: newMockClient(nil, errorMock(http.StatusUnauthorized, "Unauthorized error")), |
|
| 71 |
+ client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), |
|
| 72 | 72 |
} |
| 73 | 73 |
privilegeFunc := func() (string, error) {
|
| 74 | 74 |
return "a-auth-header", nil |
| ... | ... |
@@ -84,7 +84,7 @@ func TestImagePushWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing.T) |
| 84 | 84 |
func TestImagePushWithPrivilegedFuncNoError(t *testing.T) {
|
| 85 | 85 |
expectedURL := "/images/myimage/push" |
| 86 | 86 |
client := &Client{
|
| 87 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 87 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 88 | 88 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 89 | 89 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 90 | 90 |
} |
| ... | ... |
@@ -149,7 +149,7 @@ func TestImagePushWithoutErrors(t *testing.T) {
|
| 149 | 149 |
} |
| 150 | 150 |
for _, pullCase := range pullCases {
|
| 151 | 151 |
client := &Client{
|
| 152 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 152 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 153 | 153 |
expectedURL := fmt.Sprintf(expectedURLFormat, pullCase.expectedImage) |
| 154 | 154 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 155 | 155 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestImageRemoveError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
_, err := client.ImageRemove(context.Background(), "image_id", types.ImageRemoveOptions{})
|
| ... | ... |
@@ -49,7 +49,7 @@ func TestImageRemove(t *testing.T) {
|
| 49 | 49 |
} |
| 50 | 50 |
for _, removeCase := range removeCases {
|
| 51 | 51 |
client := &Client{
|
| 52 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 52 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 53 | 53 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 54 | 54 |
return nil, fmt.Errorf("expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 55 | 55 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestImageSaveError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
_, err := client.ImageSave(context.Background(), []string{"nothing"})
|
| 21 | 21 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -26,7 +26,7 @@ func TestImageSaveError(t *testing.T) {
|
| 26 | 26 |
func TestImageSave(t *testing.T) {
|
| 27 | 27 |
expectedURL := "/images/get" |
| 28 | 28 |
client := &Client{
|
| 29 |
- transport: newMockClient(nil, func(r *http.Request) (*http.Response, error) {
|
|
| 29 |
+ client: newMockClient(func(r *http.Request) (*http.Response, error) {
|
|
| 30 | 30 |
if !strings.HasPrefix(r.URL.Path, expectedURL) {
|
| 31 | 31 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, r.URL)
|
| 32 | 32 |
} |
| ... | ... |
@@ -18,7 +18,7 @@ import ( |
| 18 | 18 |
|
| 19 | 19 |
func TestImageSearchAnyError(t *testing.T) {
|
| 20 | 20 |
client := &Client{
|
| 21 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 21 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 22 | 22 |
} |
| 23 | 23 |
_, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{})
|
| 24 | 24 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -28,7 +28,7 @@ func TestImageSearchAnyError(t *testing.T) {
|
| 28 | 28 |
|
| 29 | 29 |
func TestImageSearchStatusUnauthorizedError(t *testing.T) {
|
| 30 | 30 |
client := &Client{
|
| 31 |
- transport: newMockClient(nil, errorMock(http.StatusUnauthorized, "Unauthorized error")), |
|
| 31 |
+ client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), |
|
| 32 | 32 |
} |
| 33 | 33 |
_, err := client.ImageSearch(context.Background(), "some-image", types.ImageSearchOptions{})
|
| 34 | 34 |
if err == nil || err.Error() != "Error response from daemon: Unauthorized error" {
|
| ... | ... |
@@ -38,7 +38,7 @@ func TestImageSearchStatusUnauthorizedError(t *testing.T) {
|
| 38 | 38 |
|
| 39 | 39 |
func TestImageSearchWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) {
|
| 40 | 40 |
client := &Client{
|
| 41 |
- transport: newMockClient(nil, errorMock(http.StatusUnauthorized, "Unauthorized error")), |
|
| 41 |
+ client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), |
|
| 42 | 42 |
} |
| 43 | 43 |
privilegeFunc := func() (string, error) {
|
| 44 | 44 |
return "", fmt.Errorf("Error requesting privilege")
|
| ... | ... |
@@ -53,7 +53,7 @@ func TestImageSearchWithUnauthorizedErrorAndPrivilegeFuncError(t *testing.T) {
|
| 53 | 53 |
|
| 54 | 54 |
func TestImageSearchWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing.T) {
|
| 55 | 55 |
client := &Client{
|
| 56 |
- transport: newMockClient(nil, errorMock(http.StatusUnauthorized, "Unauthorized error")), |
|
| 56 |
+ client: newMockClient(errorMock(http.StatusUnauthorized, "Unauthorized error")), |
|
| 57 | 57 |
} |
| 58 | 58 |
privilegeFunc := func() (string, error) {
|
| 59 | 59 |
return "a-auth-header", nil |
| ... | ... |
@@ -69,7 +69,7 @@ func TestImageSearchWithUnauthorizedErrorAndAnotherUnauthorizedError(t *testing. |
| 69 | 69 |
func TestImageSearchWithPrivilegedFuncNoError(t *testing.T) {
|
| 70 | 70 |
expectedURL := "/images/search" |
| 71 | 71 |
client := &Client{
|
| 72 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 72 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 73 | 73 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 74 | 74 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 75 | 75 |
} |
| ... | ... |
@@ -126,7 +126,7 @@ func TestImageSearchWithoutErrors(t *testing.T) {
|
| 126 | 126 |
expectedFilters := `{"is-automated":{"true":true},"stars":{"3":true}}`
|
| 127 | 127 |
|
| 128 | 128 |
client := &Client{
|
| 129 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 129 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 130 | 130 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 131 | 131 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 132 | 132 |
} |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
|
| 14 | 14 |
func TestImageTagError(t *testing.T) {
|
| 15 | 15 |
client := &Client{
|
| 16 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 16 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 17 | 17 |
} |
| 18 | 18 |
|
| 19 | 19 |
err := client.ImageTag(context.Background(), "image_id", "repo:tag") |
| ... | ... |
@@ -26,7 +26,7 @@ func TestImageTagError(t *testing.T) {
|
| 26 | 26 |
// of distribution/reference package. |
| 27 | 27 |
func TestImageTagInvalidReference(t *testing.T) {
|
| 28 | 28 |
client := &Client{
|
| 29 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 29 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 30 | 30 |
} |
| 31 | 31 |
|
| 32 | 32 |
err := client.ImageTag(context.Background(), "image_id", "aa/asdf$$^/aa") |
| ... | ... |
@@ -93,7 +93,7 @@ func TestImageTag(t *testing.T) {
|
| 93 | 93 |
} |
| 94 | 94 |
for _, tagCase := range tagCases {
|
| 95 | 95 |
client := &Client{
|
| 96 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 96 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 97 | 97 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 98 | 98 |
return nil, fmt.Errorf("expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 99 | 99 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestInfoServerError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
_, err := client.Info(context.Background()) |
| 21 | 21 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -25,7 +25,7 @@ func TestInfoServerError(t *testing.T) {
|
| 25 | 25 |
|
| 26 | 26 |
func TestInfoInvalidResponseJSONError(t *testing.T) {
|
| 27 | 27 |
client := &Client{
|
| 28 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 28 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 29 | 29 |
return &http.Response{
|
| 30 | 30 |
StatusCode: http.StatusOK, |
| 31 | 31 |
Body: ioutil.NopCloser(bytes.NewReader([]byte("invalid json"))),
|
| ... | ... |
@@ -41,7 +41,7 @@ func TestInfoInvalidResponseJSONError(t *testing.T) {
|
| 41 | 41 |
func TestInfo(t *testing.T) {
|
| 42 | 42 |
expectedURL := "/info" |
| 43 | 43 |
client := &Client{
|
| 44 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 44 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 45 | 45 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 46 | 46 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 47 | 47 |
} |
| ... | ... |
@@ -17,7 +17,7 @@ import ( |
| 17 | 17 |
|
| 18 | 18 |
func TestNetworkConnectError(t *testing.T) {
|
| 19 | 19 |
client := &Client{
|
| 20 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 20 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 | 23 |
err := client.NetworkConnect(context.Background(), "network_id", "container_id", nil) |
| ... | ... |
@@ -30,7 +30,7 @@ func TestNetworkConnectEmptyNilEndpointSettings(t *testing.T) {
|
| 30 | 30 |
expectedURL := "/networks/network_id/connect" |
| 31 | 31 |
|
| 32 | 32 |
client := &Client{
|
| 33 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 33 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 34 | 34 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 35 | 35 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 36 | 36 |
} |
| ... | ... |
@@ -69,7 +69,7 @@ func TestNetworkConnect(t *testing.T) {
|
| 69 | 69 |
expectedURL := "/networks/network_id/connect" |
| 70 | 70 |
|
| 71 | 71 |
client := &Client{
|
| 72 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 72 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 73 | 73 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 74 | 74 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 75 | 75 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestNetworkCreateError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
_, err := client.NetworkCreate(context.Background(), "mynetwork", types.NetworkCreate{})
|
| ... | ... |
@@ -28,7 +28,7 @@ func TestNetworkCreate(t *testing.T) {
|
| 28 | 28 |
expectedURL := "/networks/create" |
| 29 | 29 |
|
| 30 | 30 |
client := &Client{
|
| 31 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 31 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 32 | 32 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 33 | 33 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 34 | 34 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestNetworkDisconnectError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
err := client.NetworkDisconnect(context.Background(), "network_id", "container_id", false) |
| ... | ... |
@@ -28,7 +28,7 @@ func TestNetworkDisconnect(t *testing.T) {
|
| 28 | 28 |
expectedURL := "/networks/network_id/disconnect" |
| 29 | 29 |
|
| 30 | 30 |
client := &Client{
|
| 31 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 31 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 32 | 32 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 33 | 33 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 34 | 34 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestNetworkInspectError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
_, err := client.NetworkInspect(context.Background(), "nothing") |
| ... | ... |
@@ -26,7 +26,7 @@ func TestNetworkInspectError(t *testing.T) {
|
| 26 | 26 |
|
| 27 | 27 |
func TestNetworkInspectContainerNotFound(t *testing.T) {
|
| 28 | 28 |
client := &Client{
|
| 29 |
- transport: newMockClient(nil, errorMock(http.StatusNotFound, "Server error")), |
|
| 29 |
+ client: newMockClient(errorMock(http.StatusNotFound, "Server error")), |
|
| 30 | 30 |
} |
| 31 | 31 |
|
| 32 | 32 |
_, err := client.NetworkInspect(context.Background(), "unknown") |
| ... | ... |
@@ -38,7 +38,7 @@ func TestNetworkInspectContainerNotFound(t *testing.T) {
|
| 38 | 38 |
func TestNetworkInspect(t *testing.T) {
|
| 39 | 39 |
expectedURL := "/networks/network_id" |
| 40 | 40 |
client := &Client{
|
| 41 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 41 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 42 | 42 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 43 | 43 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 44 | 44 |
} |
| ... | ... |
@@ -16,7 +16,7 @@ import ( |
| 16 | 16 |
|
| 17 | 17 |
func TestNetworkListError(t *testing.T) {
|
| 18 | 18 |
client := &Client{
|
| 19 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 20 | 20 |
} |
| 21 | 21 |
|
| 22 | 22 |
_, err := client.NetworkList(context.Background(), types.NetworkListOptions{
|
| ... | ... |
@@ -69,7 +69,7 @@ func TestNetworkList(t *testing.T) {
|
| 69 | 69 |
|
| 70 | 70 |
for _, listCase := range listCases {
|
| 71 | 71 |
client := &Client{
|
| 72 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 72 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 73 | 73 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 74 | 74 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 75 | 75 |
} |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
|
| 14 | 14 |
func TestNetworkRemoveError(t *testing.T) {
|
| 15 | 15 |
client := &Client{
|
| 16 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 16 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 17 | 17 |
} |
| 18 | 18 |
|
| 19 | 19 |
err := client.NetworkRemove(context.Background(), "network_id") |
| ... | ... |
@@ -26,7 +26,7 @@ func TestNetworkRemove(t *testing.T) {
|
| 26 | 26 |
expectedURL := "/networks/network_id" |
| 27 | 27 |
|
| 28 | 28 |
client := &Client{
|
| 29 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 29 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 30 | 30 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 31 | 31 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 32 | 32 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestNodeInspectError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
_, _, err := client.NodeInspectWithRaw(context.Background(), "nothing") |
| ... | ... |
@@ -26,7 +26,7 @@ func TestNodeInspectError(t *testing.T) {
|
| 26 | 26 |
|
| 27 | 27 |
func TestNodeInspectNodeNotFound(t *testing.T) {
|
| 28 | 28 |
client := &Client{
|
| 29 |
- transport: newMockClient(nil, errorMock(http.StatusNotFound, "Server error")), |
|
| 29 |
+ client: newMockClient(errorMock(http.StatusNotFound, "Server error")), |
|
| 30 | 30 |
} |
| 31 | 31 |
|
| 32 | 32 |
_, _, err := client.NodeInspectWithRaw(context.Background(), "unknown") |
| ... | ... |
@@ -38,7 +38,7 @@ func TestNodeInspectNodeNotFound(t *testing.T) {
|
| 38 | 38 |
func TestNodeInspect(t *testing.T) {
|
| 39 | 39 |
expectedURL := "/nodes/node_id" |
| 40 | 40 |
client := &Client{
|
| 41 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 41 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 42 | 42 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 43 | 43 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 44 | 44 |
} |
| ... | ... |
@@ -17,7 +17,7 @@ import ( |
| 17 | 17 |
|
| 18 | 18 |
func TestNodeListError(t *testing.T) {
|
| 19 | 19 |
client := &Client{
|
| 20 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 20 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 | 23 |
_, err := client.NodeList(context.Background(), types.NodeListOptions{})
|
| ... | ... |
@@ -54,7 +54,7 @@ func TestNodeList(t *testing.T) {
|
| 54 | 54 |
} |
| 55 | 55 |
for _, listCase := range listCases {
|
| 56 | 56 |
client := &Client{
|
| 57 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 57 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 58 | 58 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 59 | 59 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 60 | 60 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestNodeRemoveError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
err := client.NodeRemove(context.Background(), "node_id", types.NodeRemoveOptions{Force: false})
|
| ... | ... |
@@ -42,7 +42,7 @@ func TestNodeRemove(t *testing.T) {
|
| 42 | 42 |
|
| 43 | 43 |
for _, removeCase := range removeCases {
|
| 44 | 44 |
client := &Client{
|
| 45 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 45 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 46 | 46 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 47 | 47 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 48 | 48 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestNodeUpdateError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
err := client.NodeUpdate(context.Background(), "node_id", swarm.Version{}, swarm.NodeSpec{})
|
| ... | ... |
@@ -28,7 +28,7 @@ func TestNodeUpdate(t *testing.T) {
|
| 28 | 28 |
expectedURL := "/nodes/node_id/update" |
| 29 | 29 |
|
| 30 | 30 |
client := &Client{
|
| 31 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 31 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 32 | 32 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 33 | 33 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 34 | 34 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestPluginDisableError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
err := client.PluginDisable(context.Background(), "plugin_name") |
| ... | ... |
@@ -28,7 +28,7 @@ func TestPluginDisable(t *testing.T) {
|
| 28 | 28 |
expectedURL := "/plugins/plugin_name/disable" |
| 29 | 29 |
|
| 30 | 30 |
client := &Client{
|
| 31 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 31 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 32 | 32 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 33 | 33 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 34 | 34 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestPluginEnableError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
err := client.PluginEnable(context.Background(), "plugin_name") |
| ... | ... |
@@ -28,7 +28,7 @@ func TestPluginEnable(t *testing.T) {
|
| 28 | 28 |
expectedURL := "/plugins/plugin_name/enable" |
| 29 | 29 |
|
| 30 | 30 |
client := &Client{
|
| 31 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 31 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 32 | 32 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 33 | 33 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 34 | 34 |
} |
| ... | ... |
@@ -17,7 +17,7 @@ import ( |
| 17 | 17 |
|
| 18 | 18 |
func TestPluginInspectError(t *testing.T) {
|
| 19 | 19 |
client := &Client{
|
| 20 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 20 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 | 23 |
_, _, err := client.PluginInspectWithRaw(context.Background(), "nothing") |
| ... | ... |
@@ -29,7 +29,7 @@ func TestPluginInspectError(t *testing.T) {
|
| 29 | 29 |
func TestPluginInspect(t *testing.T) {
|
| 30 | 30 |
expectedURL := "/plugins/plugin_name" |
| 31 | 31 |
client := &Client{
|
| 32 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 32 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 33 | 33 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 34 | 34 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 35 | 35 |
} |
| ... | ... |
@@ -17,7 +17,7 @@ import ( |
| 17 | 17 |
|
| 18 | 18 |
func TestPluginListError(t *testing.T) {
|
| 19 | 19 |
client := &Client{
|
| 20 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 20 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 | 23 |
_, err := client.PluginList(context.Background()) |
| ... | ... |
@@ -29,7 +29,7 @@ func TestPluginListError(t *testing.T) {
|
| 29 | 29 |
func TestPluginList(t *testing.T) {
|
| 30 | 30 |
expectedURL := "/plugins" |
| 31 | 31 |
client := &Client{
|
| 32 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 32 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 33 | 33 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 34 | 34 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 35 | 35 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestPluginPushError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
err := client.PluginPush(context.Background(), "plugin_name", "") |
| ... | ... |
@@ -28,7 +28,7 @@ func TestPluginPush(t *testing.T) {
|
| 28 | 28 |
expectedURL := "/plugins/plugin_name" |
| 29 | 29 |
|
| 30 | 30 |
client := &Client{
|
| 31 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 31 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 32 | 32 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 33 | 33 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 34 | 34 |
} |
| ... | ... |
@@ -17,7 +17,7 @@ import ( |
| 17 | 17 |
|
| 18 | 18 |
func TestPluginRemoveError(t *testing.T) {
|
| 19 | 19 |
client := &Client{
|
| 20 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 20 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 | 23 |
err := client.PluginRemove(context.Background(), "plugin_name", types.PluginRemoveOptions{})
|
| ... | ... |
@@ -30,7 +30,7 @@ func TestPluginRemove(t *testing.T) {
|
| 30 | 30 |
expectedURL := "/plugins/plugin_name" |
| 31 | 31 |
|
| 32 | 32 |
client := &Client{
|
| 33 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 33 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 34 | 34 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 35 | 35 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 36 | 36 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestPluginSetError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
err := client.PluginSet(context.Background(), "plugin_name", []string{})
|
| ... | ... |
@@ -28,7 +28,7 @@ func TestPluginSet(t *testing.T) {
|
| 28 | 28 |
expectedURL := "/plugins/plugin_name/set" |
| 29 | 29 |
|
| 30 | 30 |
client := &Client{
|
| 31 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 31 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 32 | 32 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 33 | 33 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 34 | 34 |
} |
| ... | ... |
@@ -13,9 +13,9 @@ import ( |
| 13 | 13 |
|
| 14 | 14 |
"github.com/docker/docker/api/types" |
| 15 | 15 |
"github.com/docker/docker/api/types/versions" |
| 16 |
- "github.com/docker/docker/client/transport/cancellable" |
|
| 17 | 16 |
"github.com/pkg/errors" |
| 18 | 17 |
"golang.org/x/net/context" |
| 18 |
+ "golang.org/x/net/context/ctxhttp" |
|
| 19 | 19 |
) |
| 20 | 20 |
|
| 21 | 21 |
// serverResponse is a wrapper for http API responses. |
| ... | ... |
@@ -98,20 +98,27 @@ func (cli *Client) sendClientRequest(ctx context.Context, method, path string, q |
| 98 | 98 |
// need a valid and meaningful host name. (See #189) |
| 99 | 99 |
req.Host = "docker" |
| 100 | 100 |
} |
| 101 |
+ |
|
| 102 |
+ scheme, err := resolveScheme(cli.client.Transport) |
|
| 103 |
+ if err != nil {
|
|
| 104 |
+ return serverResp, err |
|
| 105 |
+ } |
|
| 106 |
+ |
|
| 101 | 107 |
req.URL.Host = cli.addr |
| 102 |
- req.URL.Scheme = cli.transport.Scheme() |
|
| 108 |
+ req.URL.Scheme = scheme |
|
| 103 | 109 |
|
| 104 | 110 |
if expectedPayload && req.Header.Get("Content-Type") == "" {
|
| 105 | 111 |
req.Header.Set("Content-Type", "text/plain")
|
| 106 | 112 |
} |
| 107 | 113 |
|
| 108 |
- resp, err := cancellable.Do(ctx, cli.transport, req) |
|
| 114 |
+ resp, err := ctxhttp.Do(ctx, cli.client, req) |
|
| 109 | 115 |
if err != nil {
|
| 110 |
- if !cli.transport.Secure() && strings.Contains(err.Error(), "malformed HTTP response") {
|
|
| 116 |
+ |
|
| 117 |
+ if scheme == "https" && strings.Contains(err.Error(), "malformed HTTP response") {
|
|
| 111 | 118 |
return serverResp, fmt.Errorf("%v.\n* Are you trying to connect to a TLS-enabled daemon without TLS?", err)
|
| 112 | 119 |
} |
| 113 | 120 |
|
| 114 |
- if cli.transport.Secure() && strings.Contains(err.Error(), "bad certificate") {
|
|
| 121 |
+ if scheme == "https" && strings.Contains(err.Error(), "bad certificate") {
|
|
| 115 | 122 |
return serverResp, fmt.Errorf("The server probably has client authentication (--tlsverify) enabled. Please check your TLS client certification settings: %v", err)
|
| 116 | 123 |
} |
| 117 | 124 |
|
| ... | ... |
@@ -50,7 +50,7 @@ func TestSetHostHeader(t *testing.T) {
|
| 50 | 50 |
} |
| 51 | 51 |
|
| 52 | 52 |
client := &Client{
|
| 53 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 53 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 54 | 54 |
if !strings.HasPrefix(req.URL.Path, testURL) {
|
| 55 | 55 |
return nil, fmt.Errorf("Test Case #%d: Expected URL %q, got %q", c, testURL, req.URL)
|
| 56 | 56 |
} |
| ... | ... |
@@ -65,6 +65,7 @@ func TestSetHostHeader(t *testing.T) {
|
| 65 | 65 |
Body: ioutil.NopCloser(bytes.NewReader(([]byte("")))),
|
| 66 | 66 |
}, nil |
| 67 | 67 |
}), |
| 68 |
+ |
|
| 68 | 69 |
proto: proto, |
| 69 | 70 |
addr: addr, |
| 70 | 71 |
basePath: basePath, |
| ... | ... |
@@ -82,7 +83,7 @@ func TestSetHostHeader(t *testing.T) {
|
| 82 | 82 |
// errors returned as JSON |
| 83 | 83 |
func TestPlainTextError(t *testing.T) {
|
| 84 | 84 |
client := &Client{
|
| 85 |
- transport: newMockClient(nil, plainTextErrorMock(http.StatusInternalServerError, "Server error")), |
|
| 85 |
+ client: newMockClient(plainTextErrorMock(http.StatusInternalServerError, "Server error")), |
|
| 86 | 86 |
} |
| 87 | 87 |
_, err := client.ContainerList(context.Background(), types.ContainerListOptions{})
|
| 88 | 88 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -16,7 +16,7 @@ import ( |
| 16 | 16 |
|
| 17 | 17 |
func TestServiceCreateError(t *testing.T) {
|
| 18 | 18 |
client := &Client{
|
| 19 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 20 | 20 |
} |
| 21 | 21 |
_, err := client.ServiceCreate(context.Background(), swarm.ServiceSpec{}, types.ServiceCreateOptions{})
|
| 22 | 22 |
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
| ... | ... |
@@ -27,7 +27,7 @@ func TestServiceCreateError(t *testing.T) {
|
| 27 | 27 |
func TestServiceCreate(t *testing.T) {
|
| 28 | 28 |
expectedURL := "/services/create" |
| 29 | 29 |
client := &Client{
|
| 30 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 30 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 31 | 31 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 32 | 32 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 33 | 33 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestServiceInspectError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
_, _, err := client.ServiceInspectWithRaw(context.Background(), "nothing") |
| ... | ... |
@@ -26,7 +26,7 @@ func TestServiceInspectError(t *testing.T) {
|
| 26 | 26 |
|
| 27 | 27 |
func TestServiceInspectServiceNotFound(t *testing.T) {
|
| 28 | 28 |
client := &Client{
|
| 29 |
- transport: newMockClient(nil, errorMock(http.StatusNotFound, "Server error")), |
|
| 29 |
+ client: newMockClient(errorMock(http.StatusNotFound, "Server error")), |
|
| 30 | 30 |
} |
| 31 | 31 |
|
| 32 | 32 |
_, _, err := client.ServiceInspectWithRaw(context.Background(), "unknown") |
| ... | ... |
@@ -38,7 +38,7 @@ func TestServiceInspectServiceNotFound(t *testing.T) {
|
| 38 | 38 |
func TestServiceInspect(t *testing.T) {
|
| 39 | 39 |
expectedURL := "/services/service_id" |
| 40 | 40 |
client := &Client{
|
| 41 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 41 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 42 | 42 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 43 | 43 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 44 | 44 |
} |
| ... | ... |
@@ -17,7 +17,7 @@ import ( |
| 17 | 17 |
|
| 18 | 18 |
func TestServiceListError(t *testing.T) {
|
| 19 | 19 |
client := &Client{
|
| 20 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 20 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 | 23 |
_, err := client.ServiceList(context.Background(), types.ServiceListOptions{})
|
| ... | ... |
@@ -54,7 +54,7 @@ func TestServiceList(t *testing.T) {
|
| 54 | 54 |
} |
| 55 | 55 |
for _, listCase := range listCases {
|
| 56 | 56 |
client := &Client{
|
| 57 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 57 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 58 | 58 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 59 | 59 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 60 | 60 |
} |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
|
| 14 | 14 |
func TestServiceRemoveError(t *testing.T) {
|
| 15 | 15 |
client := &Client{
|
| 16 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 16 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 17 | 17 |
} |
| 18 | 18 |
|
| 19 | 19 |
err := client.ServiceRemove(context.Background(), "service_id") |
| ... | ... |
@@ -26,7 +26,7 @@ func TestServiceRemove(t *testing.T) {
|
| 26 | 26 |
expectedURL := "/services/service_id" |
| 27 | 27 |
|
| 28 | 28 |
client := &Client{
|
| 29 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 29 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 30 | 30 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 31 | 31 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 32 | 32 |
} |
| ... | ... |
@@ -16,7 +16,7 @@ import ( |
| 16 | 16 |
|
| 17 | 17 |
func TestServiceUpdateError(t *testing.T) {
|
| 18 | 18 |
client := &Client{
|
| 19 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 20 | 20 |
} |
| 21 | 21 |
|
| 22 | 22 |
err := client.ServiceUpdate(context.Background(), "service_id", swarm.Version{}, swarm.ServiceSpec{}, types.ServiceUpdateOptions{})
|
| ... | ... |
@@ -51,7 +51,7 @@ func TestServiceUpdate(t *testing.T) {
|
| 51 | 51 |
|
| 52 | 52 |
for _, updateCase := range updateCases {
|
| 53 | 53 |
client := &Client{
|
| 54 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 54 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 55 | 55 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 56 | 56 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 57 | 57 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestSwarmInitError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
_, err := client.SwarmInit(context.Background(), swarm.InitRequest{})
|
| ... | ... |
@@ -28,7 +28,7 @@ func TestSwarmInit(t *testing.T) {
|
| 28 | 28 |
expectedURL := "/swarm/init" |
| 29 | 29 |
|
| 30 | 30 |
client := &Client{
|
| 31 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 31 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 32 | 32 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 33 | 33 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 34 | 34 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestSwarmInspectError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
_, err := client.SwarmInspect(context.Background()) |
| ... | ... |
@@ -27,7 +27,7 @@ func TestSwarmInspectError(t *testing.T) {
|
| 27 | 27 |
func TestSwarmInspect(t *testing.T) {
|
| 28 | 28 |
expectedURL := "/swarm" |
| 29 | 29 |
client := &Client{
|
| 30 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 30 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 31 | 31 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 32 | 32 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 33 | 33 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestSwarmJoinError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
err := client.SwarmJoin(context.Background(), swarm.JoinRequest{})
|
| ... | ... |
@@ -28,7 +28,7 @@ func TestSwarmJoin(t *testing.T) {
|
| 28 | 28 |
expectedURL := "/swarm/join" |
| 29 | 29 |
|
| 30 | 30 |
client := &Client{
|
| 31 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 31 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 32 | 32 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 33 | 33 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 34 | 34 |
} |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
|
| 14 | 14 |
func TestSwarmLeaveError(t *testing.T) {
|
| 15 | 15 |
client := &Client{
|
| 16 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 16 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 17 | 17 |
} |
| 18 | 18 |
|
| 19 | 19 |
err := client.SwarmLeave(context.Background(), false) |
| ... | ... |
@@ -40,7 +40,7 @@ func TestSwarmLeave(t *testing.T) {
|
| 40 | 40 |
|
| 41 | 41 |
for _, leaveCase := range leaveCases {
|
| 42 | 42 |
client := &Client{
|
| 43 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 43 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 44 | 44 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 45 | 45 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 46 | 46 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestSwarmUpdateError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
err := client.SwarmUpdate(context.Background(), swarm.Version{}, swarm.Spec{}, swarm.UpdateFlags{})
|
| ... | ... |
@@ -28,7 +28,7 @@ func TestSwarmUpdate(t *testing.T) {
|
| 28 | 28 |
expectedURL := "/swarm/update" |
| 29 | 29 |
|
| 30 | 30 |
client := &Client{
|
| 31 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 31 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 32 | 32 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 33 | 33 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 34 | 34 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestTaskInspectError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
_, _, err := client.TaskInspectWithRaw(context.Background(), "nothing") |
| ... | ... |
@@ -27,7 +27,7 @@ func TestTaskInspectError(t *testing.T) {
|
| 27 | 27 |
func TestTaskInspect(t *testing.T) {
|
| 28 | 28 |
expectedURL := "/tasks/task_id" |
| 29 | 29 |
client := &Client{
|
| 30 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 30 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 31 | 31 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 32 | 32 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 33 | 33 |
} |
| ... | ... |
@@ -17,7 +17,7 @@ import ( |
| 17 | 17 |
|
| 18 | 18 |
func TestTaskListError(t *testing.T) {
|
| 19 | 19 |
client := &Client{
|
| 20 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 20 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 | 23 |
_, err := client.TaskList(context.Background(), types.TaskListOptions{})
|
| ... | ... |
@@ -54,7 +54,7 @@ func TestTaskList(t *testing.T) {
|
| 54 | 54 |
} |
| 55 | 55 |
for _, listCase := range listCases {
|
| 56 | 56 |
client := &Client{
|
| 57 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 57 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 58 | 58 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 59 | 59 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 60 | 60 |
} |
| 61 | 61 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,51 @@ |
| 0 |
+package client |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "crypto/tls" |
|
| 4 |
+ "errors" |
|
| 5 |
+ "net/http" |
|
| 6 |
+) |
|
| 7 |
+ |
|
| 8 |
+var errTLSConfigUnavailable = errors.New("TLSConfig unavailable")
|
|
| 9 |
+ |
|
| 10 |
+// transportFunc allows us to inject a mock transport for testing. We define it |
|
| 11 |
+// here so we can detect the tlsconfig and return nil for only this type. |
|
| 12 |
+type transportFunc func(*http.Request) (*http.Response, error) |
|
| 13 |
+ |
|
| 14 |
+func (tf transportFunc) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
| 15 |
+ return tf(req) |
|
| 16 |
+} |
|
| 17 |
+ |
|
| 18 |
+// resolveTLSConfig attempts to resolve the tls configuration from the |
|
| 19 |
+// RoundTripper. |
|
| 20 |
+func resolveTLSConfig(transport http.RoundTripper) (*tls.Config, error) {
|
|
| 21 |
+ switch tr := transport.(type) {
|
|
| 22 |
+ case *http.Transport: |
|
| 23 |
+ return tr.TLSClientConfig, nil |
|
| 24 |
+ case transportFunc: |
|
| 25 |
+ return nil, nil // detect this type for testing. |
|
| 26 |
+ default: |
|
| 27 |
+ return nil, errTLSConfigUnavailable |
|
| 28 |
+ } |
|
| 29 |
+} |
|
| 30 |
+ |
|
| 31 |
+// resolveScheme detects a tls config on the transport and returns the |
|
| 32 |
+// appropriate http scheme. |
|
| 33 |
+// |
|
| 34 |
+// TODO(stevvooe): This isn't really the right way to write clients in Go. |
|
| 35 |
+// `NewClient` should probably only take an `*http.Client` and work from there. |
|
| 36 |
+// Unfortunately, the model of having a host-ish/url-thingy as the connection |
|
| 37 |
+// string has us confusing protocol and transport layers. We continue doing |
|
| 38 |
+// this to avoid breaking existing clients but this should be addressed. |
|
| 39 |
+func resolveScheme(transport http.RoundTripper) (string, error) {
|
|
| 40 |
+ c, err := resolveTLSConfig(transport) |
|
| 41 |
+ if err != nil {
|
|
| 42 |
+ return "", err |
|
| 43 |
+ } |
|
| 44 |
+ |
|
| 45 |
+ if c != nil {
|
|
| 46 |
+ return "https", nil |
|
| 47 |
+ } |
|
| 48 |
+ |
|
| 49 |
+ return "http", nil |
|
| 50 |
+} |
| 0 | 51 |
deleted file mode 100644 |
| ... | ... |
@@ -1,27 +0,0 @@ |
| 1 |
-Copyright (c) 2009 The Go Authors. All rights reserved. |
|
| 2 |
- |
|
| 3 |
-Redistribution and use in source and binary forms, with or without |
|
| 4 |
-modification, are permitted provided that the following conditions are |
|
| 5 |
-met: |
|
| 6 |
- |
|
| 7 |
- * Redistributions of source code must retain the above copyright |
|
| 8 |
-notice, this list of conditions and the following disclaimer. |
|
| 9 |
- * Redistributions in binary form must reproduce the above |
|
| 10 |
-copyright notice, this list of conditions and the following disclaimer |
|
| 11 |
-in the documentation and/or other materials provided with the |
|
| 12 |
-distribution. |
|
| 13 |
- * Neither the name of Google Inc. nor the names of its |
|
| 14 |
-contributors may be used to endorse or promote products derived from |
|
| 15 |
-this software without specific prior written permission. |
|
| 16 |
- |
|
| 17 |
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
| 18 |
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
| 19 |
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
| 20 |
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
| 21 |
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
| 22 |
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
| 23 |
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
| 24 |
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
| 25 |
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
| 26 |
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
| 27 |
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,23 +0,0 @@ |
| 1 |
-// Copyright 2015 The Go Authors. All rights reserved. |
|
| 2 |
-// Use of this source code is governed by a BSD-style |
|
| 3 |
-// license that can be found in the LICENSE file. |
|
| 4 |
- |
|
| 5 |
-// +build go1.5 |
|
| 6 |
- |
|
| 7 |
-package cancellable |
|
| 8 |
- |
|
| 9 |
-import ( |
|
| 10 |
- "net/http" |
|
| 11 |
- |
|
| 12 |
- "github.com/docker/docker/client/transport" |
|
| 13 |
-) |
|
| 14 |
- |
|
| 15 |
-func canceler(client transport.Sender, req *http.Request) func() {
|
|
| 16 |
- // TODO(djd): Respect any existing value of req.Cancel. |
|
| 17 |
- ch := make(chan struct{})
|
|
| 18 |
- req.Cancel = ch |
|
| 19 |
- |
|
| 20 |
- return func() {
|
|
| 21 |
- close(ch) |
|
| 22 |
- } |
|
| 23 |
-} |
| 24 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,27 +0,0 @@ |
| 1 |
-// Copyright 2015 The Go Authors. All rights reserved. |
|
| 2 |
-// Use of this source code is governed by a BSD-style |
|
| 3 |
-// license that can be found in the LICENSE file. |
|
| 4 |
- |
|
| 5 |
-// +build !go1.5 |
|
| 6 |
- |
|
| 7 |
-package cancellable |
|
| 8 |
- |
|
| 9 |
-import ( |
|
| 10 |
- "net/http" |
|
| 11 |
- |
|
| 12 |
- "github.com/docker/docker/client/transport" |
|
| 13 |
-) |
|
| 14 |
- |
|
| 15 |
-type requestCanceler interface {
|
|
| 16 |
- CancelRequest(*http.Request) |
|
| 17 |
-} |
|
| 18 |
- |
|
| 19 |
-func canceler(client transport.Sender, req *http.Request) func() {
|
|
| 20 |
- rc, ok := client.(requestCanceler) |
|
| 21 |
- if !ok {
|
|
| 22 |
- return func() {}
|
|
| 23 |
- } |
|
| 24 |
- return func() {
|
|
| 25 |
- rc.CancelRequest(req) |
|
| 26 |
- } |
|
| 27 |
-} |
| 28 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,115 +0,0 @@ |
| 1 |
-// Copyright 2015 The Go Authors. All rights reserved. |
|
| 2 |
-// Use of this source code is governed by a BSD-style |
|
| 3 |
-// license that can be found in the LICENSE file. |
|
| 4 |
- |
|
| 5 |
-// Package cancellable provides helper function to cancel http requests. |
|
| 6 |
-package cancellable |
|
| 7 |
- |
|
| 8 |
-import ( |
|
| 9 |
- "io" |
|
| 10 |
- "net/http" |
|
| 11 |
- "sync" |
|
| 12 |
- |
|
| 13 |
- "github.com/docker/docker/client/transport" |
|
| 14 |
- |
|
| 15 |
- "golang.org/x/net/context" |
|
| 16 |
-) |
|
| 17 |
- |
|
| 18 |
-func nop() {}
|
|
| 19 |
- |
|
| 20 |
-var ( |
|
| 21 |
- testHookContextDoneBeforeHeaders = nop |
|
| 22 |
- testHookDoReturned = nop |
|
| 23 |
- testHookDidBodyClose = nop |
|
| 24 |
-) |
|
| 25 |
- |
|
| 26 |
-// Do sends an HTTP request with the provided transport.Sender and returns an HTTP response. |
|
| 27 |
-// If the client is nil, http.DefaultClient is used. |
|
| 28 |
-// If the context is canceled or times out, ctx.Err() will be returned. |
|
| 29 |
-// |
|
| 30 |
-// FORK INFORMATION: |
|
| 31 |
-// |
|
| 32 |
-// This function deviates from the upstream version in golang.org/x/net/context/ctxhttp by |
|
| 33 |
-// taking a Sender interface rather than a *http.Client directly. That allow us to use |
|
| 34 |
-// this function with mocked clients and hijacked connections. |
|
| 35 |
-func Do(ctx context.Context, client transport.Sender, req *http.Request) (*http.Response, error) {
|
|
| 36 |
- if client == nil {
|
|
| 37 |
- client = http.DefaultClient |
|
| 38 |
- } |
|
| 39 |
- |
|
| 40 |
- // Request cancelation changed in Go 1.5, see canceler.go and canceler_go14.go. |
|
| 41 |
- cancel := canceler(client, req) |
|
| 42 |
- |
|
| 43 |
- type responseAndError struct {
|
|
| 44 |
- resp *http.Response |
|
| 45 |
- err error |
|
| 46 |
- } |
|
| 47 |
- result := make(chan responseAndError, 1) |
|
| 48 |
- |
|
| 49 |
- go func() {
|
|
| 50 |
- resp, err := client.Do(req) |
|
| 51 |
- testHookDoReturned() |
|
| 52 |
- result <- responseAndError{resp, err}
|
|
| 53 |
- }() |
|
| 54 |
- |
|
| 55 |
- var resp *http.Response |
|
| 56 |
- |
|
| 57 |
- select {
|
|
| 58 |
- case <-ctx.Done(): |
|
| 59 |
- testHookContextDoneBeforeHeaders() |
|
| 60 |
- cancel() |
|
| 61 |
- // Clean up after the goroutine calling client.Do: |
|
| 62 |
- go func() {
|
|
| 63 |
- if r := <-result; r.resp != nil && r.resp.Body != nil {
|
|
| 64 |
- testHookDidBodyClose() |
|
| 65 |
- r.resp.Body.Close() |
|
| 66 |
- } |
|
| 67 |
- }() |
|
| 68 |
- return nil, ctx.Err() |
|
| 69 |
- case r := <-result: |
|
| 70 |
- var err error |
|
| 71 |
- resp, err = r.resp, r.err |
|
| 72 |
- if err != nil {
|
|
| 73 |
- return resp, err |
|
| 74 |
- } |
|
| 75 |
- } |
|
| 76 |
- |
|
| 77 |
- c := make(chan struct{})
|
|
| 78 |
- go func() {
|
|
| 79 |
- select {
|
|
| 80 |
- case <-ctx.Done(): |
|
| 81 |
- cancel() |
|
| 82 |
- case <-c: |
|
| 83 |
- // The response's Body is closed. |
|
| 84 |
- } |
|
| 85 |
- }() |
|
| 86 |
- resp.Body = ¬ifyingReader{ReadCloser: resp.Body, notify: c}
|
|
| 87 |
- |
|
| 88 |
- return resp, nil |
|
| 89 |
-} |
|
| 90 |
- |
|
| 91 |
-// notifyingReader is an io.ReadCloser that closes the notify channel after |
|
| 92 |
-// Close is called or a Read fails on the underlying ReadCloser. |
|
| 93 |
-type notifyingReader struct {
|
|
| 94 |
- io.ReadCloser |
|
| 95 |
- notify chan<- struct{}
|
|
| 96 |
- notifyOnce sync.Once |
|
| 97 |
-} |
|
| 98 |
- |
|
| 99 |
-func (r *notifyingReader) Read(p []byte) (int, error) {
|
|
| 100 |
- n, err := r.ReadCloser.Read(p) |
|
| 101 |
- if err != nil {
|
|
| 102 |
- r.notifyOnce.Do(func() {
|
|
| 103 |
- close(r.notify) |
|
| 104 |
- }) |
|
| 105 |
- } |
|
| 106 |
- return n, err |
|
| 107 |
-} |
|
| 108 |
- |
|
| 109 |
-func (r *notifyingReader) Close() error {
|
|
| 110 |
- err := r.ReadCloser.Close() |
|
| 111 |
- r.notifyOnce.Do(func() {
|
|
| 112 |
- close(r.notify) |
|
| 113 |
- }) |
|
| 114 |
- return err |
|
| 115 |
-} |
| 116 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,47 +0,0 @@ |
| 1 |
-package transport |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "crypto/tls" |
|
| 5 |
- "net/http" |
|
| 6 |
-) |
|
| 7 |
- |
|
| 8 |
-// Sender is an interface that clients must implement |
|
| 9 |
-// to be able to send requests to a remote connection. |
|
| 10 |
-type Sender interface {
|
|
| 11 |
- // Do sends request to a remote endpoint. |
|
| 12 |
- Do(*http.Request) (*http.Response, error) |
|
| 13 |
-} |
|
| 14 |
- |
|
| 15 |
-// Client is an interface that abstracts all remote connections. |
|
| 16 |
-type Client interface {
|
|
| 17 |
- Sender |
|
| 18 |
- // Secure tells whether the connection is secure or not. |
|
| 19 |
- Secure() bool |
|
| 20 |
- // Scheme returns the connection protocol the client uses. |
|
| 21 |
- Scheme() string |
|
| 22 |
- // TLSConfig returns any TLS configuration the client uses. |
|
| 23 |
- TLSConfig() *tls.Config |
|
| 24 |
-} |
|
| 25 |
- |
|
| 26 |
-// tlsInfo returns information about the TLS configuration. |
|
| 27 |
-type tlsInfo struct {
|
|
| 28 |
- tlsConfig *tls.Config |
|
| 29 |
-} |
|
| 30 |
- |
|
| 31 |
-// TLSConfig returns the TLS configuration. |
|
| 32 |
-func (t *tlsInfo) TLSConfig() *tls.Config {
|
|
| 33 |
- return t.tlsConfig |
|
| 34 |
-} |
|
| 35 |
- |
|
| 36 |
-// Scheme returns protocol scheme to use. |
|
| 37 |
-func (t *tlsInfo) Scheme() string {
|
|
| 38 |
- if t.tlsConfig != nil {
|
|
| 39 |
- return "https" |
|
| 40 |
- } |
|
| 41 |
- return "http" |
|
| 42 |
-} |
|
| 43 |
- |
|
| 44 |
-// Secure returns true if there is a TLS configuration. |
|
| 45 |
-func (t *tlsInfo) Secure() bool {
|
|
| 46 |
- return t.tlsConfig != nil |
|
| 47 |
-} |
| 48 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,11 +0,0 @@ |
| 1 |
-// +build go1.8 |
|
| 2 |
- |
|
| 3 |
-package transport |
|
| 4 |
- |
|
| 5 |
-import "crypto/tls" |
|
| 6 |
- |
|
| 7 |
-// TLSConfigClone returns a clone of tls.Config. This function is provided for |
|
| 8 |
-// compatibility for go1.7 that doesn't include this method in stdlib. |
|
| 9 |
-func TLSConfigClone(c *tls.Config) *tls.Config {
|
|
| 10 |
- return c.Clone() |
|
| 11 |
-} |
| 12 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,31 +0,0 @@ |
| 1 |
-// +build go1.6,!go1.7 |
|
| 2 |
- |
|
| 3 |
-package transport |
|
| 4 |
- |
|
| 5 |
-import "crypto/tls" |
|
| 6 |
- |
|
| 7 |
-// TLSConfigClone returns a clone of tls.Config. This function is provided for |
|
| 8 |
-// compatibility for go1.6 that doesn't include this method in stdlib. |
|
| 9 |
-func TLSConfigClone(c *tls.Config) *tls.Config {
|
|
| 10 |
- return &tls.Config{
|
|
| 11 |
- Rand: c.Rand, |
|
| 12 |
- Time: c.Time, |
|
| 13 |
- Certificates: c.Certificates, |
|
| 14 |
- NameToCertificate: c.NameToCertificate, |
|
| 15 |
- GetCertificate: c.GetCertificate, |
|
| 16 |
- RootCAs: c.RootCAs, |
|
| 17 |
- NextProtos: c.NextProtos, |
|
| 18 |
- ServerName: c.ServerName, |
|
| 19 |
- ClientAuth: c.ClientAuth, |
|
| 20 |
- ClientCAs: c.ClientCAs, |
|
| 21 |
- InsecureSkipVerify: c.InsecureSkipVerify, |
|
| 22 |
- CipherSuites: c.CipherSuites, |
|
| 23 |
- PreferServerCipherSuites: c.PreferServerCipherSuites, |
|
| 24 |
- SessionTicketsDisabled: c.SessionTicketsDisabled, |
|
| 25 |
- SessionTicketKey: c.SessionTicketKey, |
|
| 26 |
- ClientSessionCache: c.ClientSessionCache, |
|
| 27 |
- MinVersion: c.MinVersion, |
|
| 28 |
- MaxVersion: c.MaxVersion, |
|
| 29 |
- CurvePreferences: c.CurvePreferences, |
|
| 30 |
- } |
|
| 31 |
-} |
| 32 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,33 +0,0 @@ |
| 1 |
-// +build go1.7,!go1.8 |
|
| 2 |
- |
|
| 3 |
-package transport |
|
| 4 |
- |
|
| 5 |
-import "crypto/tls" |
|
| 6 |
- |
|
| 7 |
-// TLSConfigClone returns a clone of tls.Config. This function is provided for |
|
| 8 |
-// compatibility for go1.7 that doesn't include this method in stdlib. |
|
| 9 |
-func TLSConfigClone(c *tls.Config) *tls.Config {
|
|
| 10 |
- return &tls.Config{
|
|
| 11 |
- Rand: c.Rand, |
|
| 12 |
- Time: c.Time, |
|
| 13 |
- Certificates: c.Certificates, |
|
| 14 |
- NameToCertificate: c.NameToCertificate, |
|
| 15 |
- GetCertificate: c.GetCertificate, |
|
| 16 |
- RootCAs: c.RootCAs, |
|
| 17 |
- NextProtos: c.NextProtos, |
|
| 18 |
- ServerName: c.ServerName, |
|
| 19 |
- ClientAuth: c.ClientAuth, |
|
| 20 |
- ClientCAs: c.ClientCAs, |
|
| 21 |
- InsecureSkipVerify: c.InsecureSkipVerify, |
|
| 22 |
- CipherSuites: c.CipherSuites, |
|
| 23 |
- PreferServerCipherSuites: c.PreferServerCipherSuites, |
|
| 24 |
- SessionTicketsDisabled: c.SessionTicketsDisabled, |
|
| 25 |
- SessionTicketKey: c.SessionTicketKey, |
|
| 26 |
- ClientSessionCache: c.ClientSessionCache, |
|
| 27 |
- MinVersion: c.MinVersion, |
|
| 28 |
- MaxVersion: c.MaxVersion, |
|
| 29 |
- CurvePreferences: c.CurvePreferences, |
|
| 30 |
- DynamicRecordSizingDisabled: c.DynamicRecordSizingDisabled, |
|
| 31 |
- Renegotiation: c.Renegotiation, |
|
| 32 |
- } |
|
| 33 |
-} |
| 34 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,57 +0,0 @@ |
| 1 |
-// Package transport provides function to send request to remote endpoints. |
|
| 2 |
-package transport |
|
| 3 |
- |
|
| 4 |
-import ( |
|
| 5 |
- "fmt" |
|
| 6 |
- "net/http" |
|
| 7 |
- |
|
| 8 |
- "github.com/docker/go-connections/sockets" |
|
| 9 |
-) |
|
| 10 |
- |
|
| 11 |
-// apiTransport holds information about the http transport to connect with the API. |
|
| 12 |
-type apiTransport struct {
|
|
| 13 |
- *http.Client |
|
| 14 |
- *tlsInfo |
|
| 15 |
- transport *http.Transport |
|
| 16 |
-} |
|
| 17 |
- |
|
| 18 |
-// NewTransportWithHTTP creates a new transport based on the provided proto, address and http client. |
|
| 19 |
-// It uses Docker's default http transport configuration if the client is nil. |
|
| 20 |
-// It does not modify the client's transport if it's not nil. |
|
| 21 |
-func NewTransportWithHTTP(proto, addr string, client *http.Client) (Client, error) {
|
|
| 22 |
- var transport *http.Transport |
|
| 23 |
- |
|
| 24 |
- if client != nil {
|
|
| 25 |
- tr, ok := client.Transport.(*http.Transport) |
|
| 26 |
- if !ok {
|
|
| 27 |
- return nil, fmt.Errorf("unable to verify TLS configuration, invalid transport %v", client.Transport)
|
|
| 28 |
- } |
|
| 29 |
- transport = tr |
|
| 30 |
- } else {
|
|
| 31 |
- transport = defaultTransport(proto, addr) |
|
| 32 |
- client = &http.Client{
|
|
| 33 |
- Transport: transport, |
|
| 34 |
- } |
|
| 35 |
- } |
|
| 36 |
- |
|
| 37 |
- return &apiTransport{
|
|
| 38 |
- Client: client, |
|
| 39 |
- tlsInfo: &tlsInfo{transport.TLSClientConfig},
|
|
| 40 |
- transport: transport, |
|
| 41 |
- }, nil |
|
| 42 |
-} |
|
| 43 |
- |
|
| 44 |
-// CancelRequest stops a request execution. |
|
| 45 |
-func (a *apiTransport) CancelRequest(req *http.Request) {
|
|
| 46 |
- a.transport.CancelRequest(req) |
|
| 47 |
-} |
|
| 48 |
- |
|
| 49 |
-// defaultTransport creates a new http.Transport with Docker's |
|
| 50 |
-// default transport configuration. |
|
| 51 |
-func defaultTransport(proto, addr string) *http.Transport {
|
|
| 52 |
- tr := new(http.Transport) |
|
| 53 |
- sockets.ConfigureTransport(tr, proto, addr) |
|
| 54 |
- return tr |
|
| 55 |
-} |
|
| 56 |
- |
|
| 57 |
-var _ Client = &apiTransport{}
|
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestVolumeCreateError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
_, err := client.VolumeCreate(context.Background(), types.VolumeCreateRequest{})
|
| ... | ... |
@@ -28,7 +28,7 @@ func TestVolumeCreate(t *testing.T) {
|
| 28 | 28 |
expectedURL := "/volumes/create" |
| 29 | 29 |
|
| 30 | 30 |
client := &Client{
|
| 31 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 31 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 32 | 32 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 33 | 33 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 34 | 34 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
func TestVolumeInspectError(t *testing.T) {
|
| 17 | 17 |
client := &Client{
|
| 18 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 18 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
_, err := client.VolumeInspect(context.Background(), "nothing") |
| ... | ... |
@@ -26,7 +26,7 @@ func TestVolumeInspectError(t *testing.T) {
|
| 26 | 26 |
|
| 27 | 27 |
func TestVolumeInspectNotFound(t *testing.T) {
|
| 28 | 28 |
client := &Client{
|
| 29 |
- transport: newMockClient(nil, errorMock(http.StatusNotFound, "Server error")), |
|
| 29 |
+ client: newMockClient(errorMock(http.StatusNotFound, "Server error")), |
|
| 30 | 30 |
} |
| 31 | 31 |
|
| 32 | 32 |
_, err := client.VolumeInspect(context.Background(), "unknown") |
| ... | ... |
@@ -38,7 +38,7 @@ func TestVolumeInspectNotFound(t *testing.T) {
|
| 38 | 38 |
func TestVolumeInspect(t *testing.T) {
|
| 39 | 39 |
expectedURL := "/volumes/volume_id" |
| 40 | 40 |
client := &Client{
|
| 41 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 41 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 42 | 42 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 43 | 43 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 44 | 44 |
} |
| ... | ... |
@@ -16,7 +16,7 @@ import ( |
| 16 | 16 |
|
| 17 | 17 |
func TestVolumeListError(t *testing.T) {
|
| 18 | 18 |
client := &Client{
|
| 19 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 19 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 20 | 20 |
} |
| 21 | 21 |
|
| 22 | 22 |
_, err := client.VolumeList(context.Background(), filters.NewArgs()) |
| ... | ... |
@@ -59,7 +59,7 @@ func TestVolumeList(t *testing.T) {
|
| 59 | 59 |
|
| 60 | 60 |
for _, listCase := range listCases {
|
| 61 | 61 |
client := &Client{
|
| 62 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 62 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 63 | 63 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 64 | 64 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 65 | 65 |
} |
| ... | ... |
@@ -13,7 +13,7 @@ import ( |
| 13 | 13 |
|
| 14 | 14 |
func TestVolumeRemoveError(t *testing.T) {
|
| 15 | 15 |
client := &Client{
|
| 16 |
- transport: newMockClient(nil, errorMock(http.StatusInternalServerError, "Server error")), |
|
| 16 |
+ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
|
| 17 | 17 |
} |
| 18 | 18 |
|
| 19 | 19 |
err := client.VolumeRemove(context.Background(), "volume_id", false) |
| ... | ... |
@@ -26,7 +26,7 @@ func TestVolumeRemove(t *testing.T) {
|
| 26 | 26 |
expectedURL := "/volumes/volume_id" |
| 27 | 27 |
|
| 28 | 28 |
client := &Client{
|
| 29 |
- transport: newMockClient(nil, func(req *http.Request) (*http.Response, error) {
|
|
| 29 |
+ client: newMockClient(func(req *http.Request) (*http.Response, error) {
|
|
| 30 | 30 |
if !strings.HasPrefix(req.URL.Path, expectedURL) {
|
| 31 | 31 |
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
|
| 32 | 32 |
} |
| 33 | 33 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,11 @@ |
| 0 |
+// +build go1.8 |
|
| 1 |
+ |
|
| 2 |
+package tlsconfig |
|
| 3 |
+ |
|
| 4 |
+import "crypto/tls" |
|
| 5 |
+ |
|
| 6 |
+// Clone returns a clone of tls.Config. This function is provided for |
|
| 7 |
+// compatibility for go1.7 that doesn't include this method in stdlib. |
|
| 8 |
+func Clone(c *tls.Config) *tls.Config {
|
|
| 9 |
+ return c.Clone() |
|
| 10 |
+} |
| 0 | 11 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,31 @@ |
| 0 |
+// +build go1.6,!go1.7 |
|
| 1 |
+ |
|
| 2 |
+package tlsconfig |
|
| 3 |
+ |
|
| 4 |
+import "crypto/tls" |
|
| 5 |
+ |
|
| 6 |
+// Clone returns a clone of tls.Config. This function is provided for |
|
| 7 |
+// compatibility for go1.6 that doesn't include this method in stdlib. |
|
| 8 |
+func Clone(c *tls.Config) *tls.Config {
|
|
| 9 |
+ return &tls.Config{
|
|
| 10 |
+ Rand: c.Rand, |
|
| 11 |
+ Time: c.Time, |
|
| 12 |
+ Certificates: c.Certificates, |
|
| 13 |
+ NameToCertificate: c.NameToCertificate, |
|
| 14 |
+ GetCertificate: c.GetCertificate, |
|
| 15 |
+ RootCAs: c.RootCAs, |
|
| 16 |
+ NextProtos: c.NextProtos, |
|
| 17 |
+ ServerName: c.ServerName, |
|
| 18 |
+ ClientAuth: c.ClientAuth, |
|
| 19 |
+ ClientCAs: c.ClientCAs, |
|
| 20 |
+ InsecureSkipVerify: c.InsecureSkipVerify, |
|
| 21 |
+ CipherSuites: c.CipherSuites, |
|
| 22 |
+ PreferServerCipherSuites: c.PreferServerCipherSuites, |
|
| 23 |
+ SessionTicketsDisabled: c.SessionTicketsDisabled, |
|
| 24 |
+ SessionTicketKey: c.SessionTicketKey, |
|
| 25 |
+ ClientSessionCache: c.ClientSessionCache, |
|
| 26 |
+ MinVersion: c.MinVersion, |
|
| 27 |
+ MaxVersion: c.MaxVersion, |
|
| 28 |
+ CurvePreferences: c.CurvePreferences, |
|
| 29 |
+ } |
|
| 30 |
+} |
| 0 | 31 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,33 @@ |
| 0 |
+// +build go1.7,!go1.8 |
|
| 1 |
+ |
|
| 2 |
+package tlsconfig |
|
| 3 |
+ |
|
| 4 |
+import "crypto/tls" |
|
| 5 |
+ |
|
| 6 |
+// Clone returns a clone of tls.Config. This function is provided for |
|
| 7 |
+// compatibility for go1.7 that doesn't include this method in stdlib. |
|
| 8 |
+func Clone(c *tls.Config) *tls.Config {
|
|
| 9 |
+ return &tls.Config{
|
|
| 10 |
+ Rand: c.Rand, |
|
| 11 |
+ Time: c.Time, |
|
| 12 |
+ Certificates: c.Certificates, |
|
| 13 |
+ NameToCertificate: c.NameToCertificate, |
|
| 14 |
+ GetCertificate: c.GetCertificate, |
|
| 15 |
+ RootCAs: c.RootCAs, |
|
| 16 |
+ NextProtos: c.NextProtos, |
|
| 17 |
+ ServerName: c.ServerName, |
|
| 18 |
+ ClientAuth: c.ClientAuth, |
|
| 19 |
+ ClientCAs: c.ClientCAs, |
|
| 20 |
+ InsecureSkipVerify: c.InsecureSkipVerify, |
|
| 21 |
+ CipherSuites: c.CipherSuites, |
|
| 22 |
+ PreferServerCipherSuites: c.PreferServerCipherSuites, |
|
| 23 |
+ SessionTicketsDisabled: c.SessionTicketsDisabled, |
|
| 24 |
+ SessionTicketKey: c.SessionTicketKey, |
|
| 25 |
+ ClientSessionCache: c.ClientSessionCache, |
|
| 26 |
+ MinVersion: c.MinVersion, |
|
| 27 |
+ MaxVersion: c.MaxVersion, |
|
| 28 |
+ CurvePreferences: c.CurvePreferences, |
|
| 29 |
+ DynamicRecordSizingDisabled: c.DynamicRecordSizingDisabled, |
|
| 30 |
+ Renegotiation: c.Renegotiation, |
|
| 31 |
+ } |
|
| 32 |
+} |