Skip to content

Commit

Permalink
fix bodyclose linter
Browse files Browse the repository at this point in the history
  • Loading branch information
dprotaso committed Jun 24, 2024
1 parent 3e4dd92 commit 0775223
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions metrics/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ func TestMetricsExport(t *testing.T) {
// Wait for the webserver to actually start serving metrics
return wait.PollUntilContextTimeout(context.Background(), 10*time.Millisecond, 10*time.Second, true, func(ctx context.Context) (bool, error) {
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/metrics", prometheusPort))
if err != nil {
defer resp.Body.Close()
}
return err == nil && resp.StatusCode == http.StatusOK, nil
})
},
Expand Down
5 changes: 4 additions & 1 deletion network/transports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ func TestHTTPRoundTripper(t *testing.T) {
t.Run(e.label, func(t *testing.T) {
wants.Delete(e.want)
r := &http.Request{ProtoMajor: e.protoMajor}
rt.RoundTrip(r)
resp, err := rt.RoundTrip(r)
if err != nil {
defer resp.Body.Close()
}

if !wants.Has(e.want) {
t.Error("Wrong transport selected for request.")
Expand Down
15 changes: 12 additions & 3 deletions test/spoof/error_checks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ func TestDNSError(t *testing.T) {
}} {
t.Run(tt.name, func(t *testing.T) {
req, _ := http.NewRequest(http.MethodGet, tt.url, nil)
_, err := client.Do(req)
resp, err := client.Do(req)
if err != nil {
defer resp.Body.Close()
}
if dnsError := isDNSError(err); tt.dnsError != dnsError {
t.Errorf("Expected dnsError=%v, got %v", tt.dnsError, dnsError)
}
Expand Down Expand Up @@ -80,7 +83,10 @@ func TestConnectionRefused(t *testing.T) {
}} {
t.Run(tt.name, func(t *testing.T) {
req, _ := http.NewRequest(http.MethodGet, tt.url, nil)
_, err := client.Do(req)
resp, err := client.Do(req)
if err != nil {
defer resp.Body.Close()
}
if connRefused := isConnectionRefused(err); tt.connRefused != connRefused {
t.Errorf("Expected connRefused=%v, got %v", tt.connRefused, connRefused)
}
Expand Down Expand Up @@ -137,7 +143,10 @@ func TestTCPTimeout(t *testing.T) {
}} {
t.Run(tt.name, func(t *testing.T) {
req, _ := http.NewRequest(http.MethodGet, tt.url, nil)
_, err := client.Do(req)
resp, err := client.Do(req)
if err != nil {
defer resp.Body.Close()
}
if tcpTimeout := isTCPTimeout(err); tt.tcpTimeout != tcpTimeout {
t.Errorf("Expected tcpTimeout=%v, got %v", tt.tcpTimeout, tcpTimeout)
}
Expand Down
2 changes: 1 addition & 1 deletion websocket/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func NewDurableConnection(target string, messageChan chan []byte, logger *zap.Su
// by restarting the serving side of the connection behind a Kubernetes Service.
HandshakeTimeout: 3 * time.Second,
}
conn, resp, err := dialer.Dial(target, nil)
conn, resp, err := dialer.Dial(target, nil) //nolint:bodyclose
if err != nil {
if resp != nil {
dresp, _ := httputil.DumpResponse(resp, true /*body*/) // This is for logging so don't care if it fails.
Expand Down

0 comments on commit 0775223

Please sign in to comment.