Selaa lähdekoodia

pkg/plugins/transport: remove RequestFactory interface

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>
Sebastiaan van Stijn 2 vuotta sitten
vanhempi
commit
77c03221c9

+ 7 - 1
pkg/plugins/client.go

@@ -87,10 +87,16 @@ func newClientWithTransport(tr *transport.HTTPTransport, timeout time.Duration)
 	}
 }
 
+// requestFactory defines an interface that transports can implement to
+// create new requests. It's used in testing.
+type requestFactory interface {
+	NewRequest(path string, data io.Reader) (*http.Request, error)
+}
+
 // Client represents a plugin client.
 type Client struct {
 	http           *http.Client // http client to use
-	requestFactory transport.RequestFactory
+	requestFactory requestFactory
 }
 
 // RequestOpts is the set of options that can be passed into a request

+ 1 - 2
pkg/plugins/transport/http_test.go

@@ -11,8 +11,7 @@ import (
 
 func TestHTTPTransport(t *testing.T) {
 	var r io.Reader
-	roundTripper := &http.Transport{}
-	newTransport := NewHTTPTransport(roundTripper, "http", "0.0.0.0")
+	newTransport := NewHTTPTransport(&http.Transport{}, "http", "0.0.0.0")
 	request, err := newTransport.NewRequest("", r)
 	if err != nil {
 		t.Fatal(err)

+ 0 - 11
pkg/plugins/transport/transport.go

@@ -1,15 +1,4 @@
 package transport // import "github.com/docker/docker/pkg/plugins/transport"
 
-import (
-	"io"
-	"net/http"
-)
-
 // VersionMimetype is the Content-Type the engine sends to plugins.
 const VersionMimetype = "application/vnd.docker.plugins.v1.2+json"
-
-// RequestFactory defines an interface that
-// transports can implement to create new requests.
-type RequestFactory interface {
-	NewRequest(path string, data io.Reader) (*http.Request, error)
-}