Skip to content

Commit

Permalink
Remove Manual Dialouts
Browse files Browse the repository at this point in the history
Signed-off-by: Mahad Zaryab <[email protected]>
  • Loading branch information
mahadzaryab1 committed Nov 22, 2024
1 parent fabeb93 commit 6eeeb67
Showing 1 changed file with 2 additions and 46 deletions.
48 changes: 2 additions & 46 deletions cmd/query/app/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package app
import (
"bytes"
"context"
"crypto/tls"
"fmt"
"net"
"net/http"
Expand Down Expand Up @@ -135,7 +134,6 @@ var testCases = []struct {
HTTPTLSEnabled bool
GRPCTLSEnabled bool
clientTLS configtls.ClientConfig
expectError bool
expectClientError bool
expectServerFail bool
}{
Expand All @@ -147,7 +145,6 @@ var testCases = []struct {
clientTLS: configtls.ClientConfig{
Insecure: true,
},
expectError: false,
expectClientError: false,
expectServerFail: false,
},
Expand All @@ -165,7 +162,6 @@ var testCases = []struct {
Insecure: true,
ServerName: "example.com",
},
expectError: true,
expectClientError: true,
expectServerFail: false,
},
Expand All @@ -186,7 +182,6 @@ var testCases = []struct {
CAFile: testCertKeyLocation + "/example-CA-cert.pem",
},
},
expectError: true,
expectClientError: true,
expectServerFail: false,
},
Expand All @@ -207,7 +202,6 @@ var testCases = []struct {
CAFile: testCertKeyLocation + "/example-CA-cert.pem",
},
},
expectError: false,
expectClientError: false,
expectServerFail: false,
},
Expand All @@ -229,7 +223,6 @@ var testCases = []struct {
CAFile: testCertKeyLocation + "/example-CA-cert.pem",
},
},
expectError: false,
expectServerFail: false,
expectClientError: true,
},
Expand All @@ -253,7 +246,6 @@ var testCases = []struct {
KeyFile: testCertKeyLocation + "/example-client-key.pem",
},
},
expectError: false,
expectServerFail: false,
expectClientError: false,
},
Expand All @@ -278,7 +270,6 @@ var testCases = []struct {
KeyFile: testCertKeyLocation + "/example-client-key.pem",
},
},
expectError: false,
expectServerFail: false,
expectClientError: true,
},
Expand All @@ -302,7 +293,6 @@ var testCases = []struct {
KeyFile: testCertKeyLocation + "/example-client-key.pem",
},
},
expectError: false,
expectServerFail: false,
expectClientError: false,
},
Expand All @@ -326,7 +316,6 @@ var testCases = []struct {
KeyFile: testCertKeyLocation + "/example-client-key.pem",
},
},
expectError: false,
expectServerFail: false,
expectClientError: false,
},
Expand Down Expand Up @@ -362,7 +351,6 @@ func TestServerHTTPTLS(t *testing.T) {
HTTPTLSEnabled bool
GRPCTLSEnabled bool
clientTLS configtls.ClientConfig
expectError bool
expectClientError bool
expectServerFail bool
}, testlen)
Expand Down Expand Up @@ -415,39 +403,8 @@ func TestServerHTTPTLS(t *testing.T) {
require.NoError(t, server.Close())
})

var clientError error
var clientClose func() error
var clientTLSCfg *tls.Config

if serverOptions.HTTP.TLSSetting != nil {
var err0 error
clientTLSCfg, err0 = test.clientTLS.LoadTLSConfig(context.Background())

require.NoError(t, err0)
dialer := &net.Dialer{Timeout: 2 * time.Second}
conn, err1 := tls.DialWithDialer(dialer, "tcp", server.HTTPAddr(), clientTLSCfg)
clientError = err1
clientClose = nil
if conn != nil {
clientClose = conn.Close
}
} else {
conn, err1 := net.DialTimeout("tcp", server.HTTPAddr(), 2*time.Second)
clientError = err1
clientClose = nil
if conn != nil {
clientClose = conn.Close
}
}

if test.expectError {
require.Error(t, clientError)
} else {
require.NoError(t, clientError)
}
if clientClose != nil {
require.NoError(t, clientClose())
}
clientTLSCfg, err := test.clientTLS.LoadTLSConfig(context.Background())
require.NoError(t, err)

if test.HTTPTLSEnabled {
client := &http.Client{
Expand Down Expand Up @@ -505,7 +462,6 @@ func TestServerGRPCTLS(t *testing.T) {
HTTPTLSEnabled bool
GRPCTLSEnabled bool
clientTLS configtls.ClientConfig
expectError bool
expectClientError bool
expectServerFail bool
}, testlen)
Expand Down

0 comments on commit 6eeeb67

Please sign in to comment.