浏览代码

registry: debugTransport should print with testing.T.Log

It should not print to STDOUT so that it only prints the debugTransport
output if there was an error in one of the registry tests.

Signed-off-by: Tibor Vass <tibor@docker.com>
Tibor Vass 10 年之前
父节点
当前提交
78bc233a01
共有 2 个文件被更改,包括 9 次插入6 次删除
  1. 8 5
      registry/registry.go
  2. 1 1
      registry/registry_test.go

+ 8 - 5
registry/registry.go

@@ -200,23 +200,26 @@ func DockerHeaders(metaHeaders http.Header) []transport.RequestModifier {
 	return modifiers
 	return modifiers
 }
 }
 
 
-type debugTransport struct{ http.RoundTripper }
+type debugTransport struct {
+	http.RoundTripper
+	log func(...interface{})
+}
 
 
 func (tr debugTransport) RoundTrip(req *http.Request) (*http.Response, error) {
 func (tr debugTransport) RoundTrip(req *http.Request) (*http.Response, error) {
 	dump, err := httputil.DumpRequestOut(req, false)
 	dump, err := httputil.DumpRequestOut(req, false)
 	if err != nil {
 	if err != nil {
-		fmt.Println("could not dump request")
+		tr.log("could not dump request")
 	}
 	}
-	fmt.Println(string(dump))
+	tr.log(string(dump))
 	resp, err := tr.RoundTripper.RoundTrip(req)
 	resp, err := tr.RoundTripper.RoundTrip(req)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
 	dump, err = httputil.DumpResponse(resp, false)
 	dump, err = httputil.DumpResponse(resp, false)
 	if err != nil {
 	if err != nil {
-		fmt.Println("could not dump response")
+		tr.log("could not dump response")
 	}
 	}
-	fmt.Println(string(dump))
+	tr.log(string(dump))
 	return resp, err
 	return resp, err
 }
 }
 
 

+ 1 - 1
registry/registry_test.go

@@ -26,7 +26,7 @@ func spawnTestRegistrySession(t *testing.T) *Session {
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}
-	var tr http.RoundTripper = debugTransport{NewTransport(ReceiveTimeout, endpoint.IsSecure)}
+	var tr http.RoundTripper = debugTransport{NewTransport(ReceiveTimeout, endpoint.IsSecure), t.Log}
 	tr = transport.NewTransport(AuthTransport(tr, authConfig, false), DockerHeaders(nil)...)
 	tr = transport.NewTransport(AuthTransport(tr, authConfig, false), DockerHeaders(nil)...)
 	client := HTTPClient(tr)
 	client := HTTPClient(tr)
 	r, err := NewSession(client, authConfig, endpoint)
 	r, err := NewSession(client, authConfig, endpoint)