From 6640f60cc58587d49a4fcb37466cc5f753102cd3 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Mon, 1 Jun 2015 17:48:30 -0400 Subject: [PATCH] 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 --- docs/registry.go | 13 ++++++++----- docs/registry_test.go | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/registry.go b/docs/registry.go index 47bd2553..80d4268e 100644 --- a/docs/registry.go +++ b/docs/registry.go @@ -200,23 +200,26 @@ func DockerHeaders(metaHeaders http.Header) []transport.RequestModifier { 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) { dump, err := httputil.DumpRequestOut(req, false) 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) if err != nil { return nil, err } dump, err = httputil.DumpResponse(resp, false) 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 } diff --git a/docs/registry_test.go b/docs/registry_test.go index 33e86ff4..eee801d4 100644 --- a/docs/registry_test.go +++ b/docs/registry_test.go @@ -26,7 +26,7 @@ func spawnTestRegistrySession(t *testing.T) *Session { if err != nil { 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)...) client := HTTPClient(tr) r, err := NewSession(client, authConfig, endpoint)