diff options
| author | Damien Neil <dneil@google.com> | 2022-11-18 11:33:53 -0800 |
|---|---|---|
| committer | Damien Neil <dneil@google.com> | 2022-11-19 01:19:45 +0000 |
| commit | c6cdfd88c762ee746cd9579ae57e528f56f5dd00 (patch) | |
| tree | 0f2af9db073dab7f55bdc7ae99c8e3f311717f57 /src/net/http/clientserver_test.go | |
| parent | 4f0d3bcd6d2d6bc726044153bf6875d195203b32 (diff) | |
| download | go-c6cdfd88c762ee746cd9579ae57e528f56f5dd00.tar.xz | |
net/http: direct server logs to test output in tests
Set a logger in newClientServerTest that directs the server
log output to the testing.T's log, so log output gets properly
associated with the test that caused it.
Change-Id: I13686ca35c3e21adae16b2fc37ce36daea3df9d5
Reviewed-on: https://go-review.googlesource.com/c/go/+/452075
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/net/http/clientserver_test.go')
| -rw-r--r-- | src/net/http/clientserver_test.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/net/http/clientserver_test.go b/src/net/http/clientserver_test.go index 87e34cef85..da5671d9b9 100644 --- a/src/net/http/clientserver_test.go +++ b/src/net/http/clientserver_test.go @@ -170,6 +170,10 @@ func newClientServerTest(t testing.TB, mode testMode, h Handler, opts ...any) *c } } + if cst.ts.Config.ErrorLog == nil { + cst.ts.Config.ErrorLog = log.New(testLogWriter{t}, "", 0) + } + switch mode { case http1Mode: cst.ts.Start() @@ -198,6 +202,15 @@ func newClientServerTest(t testing.TB, mode testMode, h Handler, opts ...any) *c return cst } +type testLogWriter struct { + t testing.TB +} + +func (w testLogWriter) Write(b []byte) (int, error) { + w.t.Logf("server log: %v", strings.TrimSpace(string(b))) + return len(b), nil +} + // Testing the newClientServerTest helper itself. func TestNewClientServerTest(t *testing.T) { run(t, testNewClientServerTest, []testMode{http1Mode, https1Mode, http2Mode}) |
