From bf401627f20f3af71ee0d30e2dbd1460c32b7103 Mon Sep 17 00:00:00 2001 From: Israel Blancas Date: Tue, 12 Mar 2024 21:07:39 +0100 Subject: [PATCH] [chore] Add goleak tests for jaeger receiver (#31687) Related to https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/30438 Signed-off-by: Israel Blancas --- receiver/jaegerreceiver/go.mod | 1 + receiver/jaegerreceiver/jaeger_agent_test.go | 8 +++----- receiver/jaegerreceiver/package_test.go | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 receiver/jaegerreceiver/package_test.go diff --git a/receiver/jaegerreceiver/go.mod b/receiver/jaegerreceiver/go.mod index 926d00b84ada..48e9e7b07d5b 100644 --- a/receiver/jaegerreceiver/go.mod +++ b/receiver/jaegerreceiver/go.mod @@ -22,6 +22,7 @@ require ( go.opentelemetry.io/collector/semconv v0.96.1-0.20240306115632-b2693620eff6 go.opentelemetry.io/otel/metric v1.24.0 go.opentelemetry.io/otel/trace v1.24.0 + go.uber.org/goleak v1.3.0 go.uber.org/multierr v1.11.0 go.uber.org/zap v1.27.0 google.golang.org/grpc v1.62.1 diff --git a/receiver/jaegerreceiver/jaeger_agent_test.go b/receiver/jaegerreceiver/jaeger_agent_test.go index aa1e5673ba41..77e07cfca7ea 100644 --- a/receiver/jaegerreceiver/jaeger_agent_test.go +++ b/receiver/jaegerreceiver/jaeger_agent_test.go @@ -161,11 +161,9 @@ func TestJaegerHTTP(t *testing.T) { resp, err := http.Get(fmt.Sprintf("http://%s/sampling?service=test", endpoint)) assert.NoError(t, err, "should not have failed to make request") - if resp != nil { - assert.Equal(t, 500, resp.StatusCode, "should have returned 200") - return - } - t.Fail() + assert.NotNil(t, resp) + defer resp.Body.Close() + assert.Equal(t, 500, resp.StatusCode, "should have returned 200") } func testJaegerAgent(t *testing.T, agentEndpoint string, receiverConfig *configuration) { diff --git a/receiver/jaegerreceiver/package_test.go b/receiver/jaegerreceiver/package_test.go new file mode 100644 index 000000000000..79fe99141725 --- /dev/null +++ b/receiver/jaegerreceiver/package_test.go @@ -0,0 +1,14 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package jaegerreceiver + +import ( + "testing" + + "go.uber.org/goleak" +) + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m) +}