Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
emcfarlane committed Sep 18, 2023
1 parent 4c43e4b commit 1f1df5d
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions internal/connecttest/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,40 @@ import (

// StartHTTPTestServer starts an HTTP server that listens on a in memory
// network. The returned server is configured to use the in memory network.
func StartHTTPTestServer(t testing.TB, handler http.Handler) *httptest.Server {
func StartHTTPTestServer(tb testing.TB, handler http.Handler) *httptest.Server {
tb.Helper()
lis := NewMemoryListener()
svr := httptest.NewUnstartedServer(handler)
svr.Config.ErrorLog = log.New(NewTestWriter(t), "", 0)
svr.Config.ErrorLog = log.New(NewTestWriter(tb), "", 0) //nolint:forbidigo
svr.Listener = lis
svr.Start()
t.Cleanup(svr.Close)
tb.Cleanup(svr.Close)
client := svr.Client()
if transport, ok := client.Transport.(*http.Transport); ok {
transport.DialContext = lis.DialContext
} else {
t.Fatalf("unexpected transport type: %T", client.Transport)
tb.Fatalf("unexpected transport type: %T", client.Transport)
}
return svr
}

// StartHTTP2TestServer starts an HTTP/2 server that listens on a in memory
// network. The returned server is configured to use the in memory network and
// TLS.
func StartHTTP2TestServer(t testing.TB, handler http.Handler) *httptest.Server {
func StartHTTP2TestServer(tb testing.TB, handler http.Handler) *httptest.Server {
tb.Helper()
lis := NewMemoryListener()
svr := httptest.NewUnstartedServer(handler)
svr.Config.ErrorLog = log.New(NewTestWriter(t), "", 0)
svr.Config.ErrorLog = log.New(NewTestWriter(tb), "", 0) //nolint:forbidigo
svr.Listener = lis
svr.EnableHTTP2 = true
svr.StartTLS()
t.Cleanup(svr.Close)
tb.Cleanup(svr.Close)
client := svr.Client()
if transport, ok := client.Transport.(*http.Transport); ok {
transport.DialContext = lis.DialContext
} else {
t.Fatalf("unexpected transport type: %T", client.Transport)
tb.Fatalf("unexpected transport type: %T", client.Transport)
}
return svr
}
Expand All @@ -68,13 +70,14 @@ type testWriter struct {
tb testing.TB
}

func (l *testWriter) Write(p []byte) (n int, err error) {
func (l *testWriter) Write(p []byte) (int, error) {
l.tb.Log(string(p))
return
return len(p), nil
}

// NewTestWriter returns a writer that logs to the given testing.TB.
func NewTestWriter(tb testing.TB) io.Writer {
tb.Helper()
return &testWriter{tb}
}

Expand Down

0 comments on commit 1f1df5d

Please sign in to comment.