The client's transport can only be set by newClientWithTransport, which
is not exported, and always uses a transport.HTTPTransport.
However, requestFactory is mocked in one of the tests, so keep the interface,
but make it a local, non-exported one.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -87,10 +87,16 @@ func newClientWithTransport(tr *transport.HTTPTransport, timeout time.Duration) |
| 87 | 87 |
} |
| 88 | 88 |
} |
| 89 | 89 |
|
| 90 |
+// requestFactory defines an interface that transports can implement to |
|
| 91 |
+// create new requests. It's used in testing. |
|
| 92 |
+type requestFactory interface {
|
|
| 93 |
+ NewRequest(path string, data io.Reader) (*http.Request, error) |
|
| 94 |
+} |
|
| 95 |
+ |
|
| 90 | 96 |
// Client represents a plugin client. |
| 91 | 97 |
type Client struct {
|
| 92 | 98 |
http *http.Client // http client to use |
| 93 |
- requestFactory transport.RequestFactory |
|
| 99 |
+ requestFactory requestFactory |
|
| 94 | 100 |
} |
| 95 | 101 |
|
| 96 | 102 |
// RequestOpts is the set of options that can be passed into a request |
| ... | ... |
@@ -11,8 +11,7 @@ import ( |
| 11 | 11 |
|
| 12 | 12 |
func TestHTTPTransport(t *testing.T) {
|
| 13 | 13 |
var r io.Reader |
| 14 |
- roundTripper := &http.Transport{}
|
|
| 15 |
- newTransport := NewHTTPTransport(roundTripper, "http", "0.0.0.0") |
|
| 14 |
+ newTransport := NewHTTPTransport(&http.Transport{}, "http", "0.0.0.0")
|
|
| 16 | 15 |
request, err := newTransport.NewRequest("", r)
|
| 17 | 16 |
if err != nil {
|
| 18 | 17 |
t.Fatal(err) |
| ... | ... |
@@ -1,15 +1,4 @@ |
| 1 | 1 |
package transport // import "github.com/docker/docker/pkg/plugins/transport" |
| 2 | 2 |
|
| 3 |
-import ( |
|
| 4 |
- "io" |
|
| 5 |
- "net/http" |
|
| 6 |
-) |
|
| 7 |
- |
|
| 8 | 3 |
// VersionMimetype is the Content-Type the engine sends to plugins. |
| 9 | 4 |
const VersionMimetype = "application/vnd.docker.plugins.v1.2+json" |
| 10 |
- |
|
| 11 |
-// RequestFactory defines an interface that |
|
| 12 |
-// transports can implement to create new requests. |
|
| 13 |
-type RequestFactory interface {
|
|
| 14 |
- NewRequest(path string, data io.Reader) (*http.Request, error) |
|
| 15 |
-} |