From a2b1bec78d06c58edb765cad8679705103fd8326 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Tue, 16 May 2023 14:16:28 +0300 Subject: [PATCH] Refactor client server tests (#37) - remove unused field; - unlambda; - omit type declaration. --- client_server_test.go | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/client_server_test.go b/client_server_test.go index 67dd346..de21b25 100644 --- a/client_server_test.go +++ b/client_server_test.go @@ -49,7 +49,6 @@ type cstHandler struct{ *testing.T } type cstServer struct { *httptest.Server URL string - t *testing.T } const ( @@ -463,7 +462,7 @@ func TestBadMethod(t *testing.T) { })) defer s.Close() - req, err := http.NewRequest(http.MethodPost, s.URL, strings.NewReader("")) + req, err := http.NewRequest(http.MethodPost, s.URL, http.NoBody) if err != nil { t.Fatalf("NewRequest returned error %v", err) } @@ -987,11 +986,9 @@ func TestNetDialConnect(t *testing.T) { tlsClientConfig: nil, }, { - name: "HTTP server, NetDialContext undefined, shall fallback to NetDial", - server: server, - netDial: func(network, addr string) (net.Conn, error) { - return net.Dial(network, addr) - }, + name: "HTTP server, NetDialContext undefined, shall fallback to NetDial", + server: server, + netDial: net.Dial, netDialContext: nil, netDialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) { return nil, errors.New("NetDialTLSContext should not be called") @@ -1034,11 +1031,9 @@ func TestNetDialConnect(t *testing.T) { tlsClientConfig: tlsConfig, }, { - name: "HTTPS server, NetDialTLSContext and NetDialContext undefined, shall fallback to NetDial and do handshake", - server: tlsServer, - netDial: func(network, addr string) (net.Conn, error) { - return net.Dial(network, addr) - }, + name: "HTTPS server, NetDialTLSContext and NetDialContext undefined, shall fallback to NetDial and do handshake", + server: tlsServer, + netDial: net.Dial, netDialContext: nil, netDialTLSContext: nil, tlsClientConfig: tlsConfig, @@ -1117,7 +1112,7 @@ func TestNextProtos(t *testing.T) { // Asserts that Dialer.TLSClientConfig.NextProtos contains "h2" // after the Client.Get call from net/http above. - var containsHTTP2 bool = false + containsHTTP2 := false for _, proto := range d.TLSClientConfig.NextProtos { if proto == "h2" { containsHTTP2 = true