From 562d2b208decd17c39bafb910f9382638c6c71ba Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Fri, 13 Dec 2024 16:12:14 -0800 Subject: [PATCH] Ignore the false-positive --- detectors/azure/azurevm/vm.go | 3 +-- .../net/http/otelhttp/test/transport_test.go | 15 ++++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/detectors/azure/azurevm/vm.go b/detectors/azure/azurevm/vm.go index cd3a3ef27a1..f801607d11f 100644 --- a/detectors/azure/azurevm/vm.go +++ b/detectors/azure/azurevm/vm.go @@ -96,11 +96,10 @@ func (detector *ResourceDetector) getJSONMetadata(ctx context.Context) ([]byte, req.Header.Add("Metadata", "True") - resp, err := client.Do(req) + resp, err := client.Do(req) // nolint:bodyclose // False-positive. if err != nil { return nil, false, err } - defer resp.Body.Close() if resp.StatusCode == http.StatusOK { diff --git a/instrumentation/net/http/otelhttp/test/transport_test.go b/instrumentation/net/http/otelhttp/test/transport_test.go index 0e0267defee..40d394b8165 100644 --- a/instrumentation/net/http/otelhttp/test/transport_test.go +++ b/instrumentation/net/http/otelhttp/test/transport_test.go @@ -66,10 +66,8 @@ func TestTransportUsesFormatter(t *testing.T) { ) c := http.Client{Transport: tr} - res, err := c.Do(r) - if err != nil { - t.Fatal(err) - } + res, err := c.Do(r) // nolint:bodyclose // False-positive. + require.NoError(t, err) require.NoError(t, res.Body.Close()) spans := spanRecorder.Ended() @@ -100,10 +98,10 @@ func TestTransportErrorStatus(t *testing.T) { t.Fatal(err) } resp, err := c.Do(r) + if e := resp.Body.Close(); e != nil { + t.Errorf("close response body: %v", e) + } if err == nil { - if err := resp.Body.Close(); err != nil { - t.Errorf("close response body: %v", err) - } t.Fatal("transport should have returned an error, it didn't") } @@ -276,6 +274,7 @@ func TestTransportMetrics(t *testing.T) { if err != nil { t.Fatal(err) } + defer res.Body.Close() // Must read the body or else we won't get response metrics bodyBytes, err := io.ReadAll(res.Body) @@ -334,6 +333,7 @@ func TestTransportMetrics(t *testing.T) { if err != nil { t.Fatal(err) } + defer res.Body.Close() // Must read the body or else we won't get response metrics smallBuf := make([]byte, 10) @@ -402,6 +402,7 @@ func TestTransportMetrics(t *testing.T) { if err != nil { t.Fatal(err) } + defer res.Body.Close() // Must read the body or else we won't get response metrics smallBuf := make([]byte, 10)