Skip to content

Commit

Permalink
review feedback: add goleak verification to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiangreco committed Nov 22, 2024
1 parent aa11097 commit 335fb90
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
)

func TestConnectionInfoRun(t *testing.T) {
defer goleak.VerifyNone(t)

const baseExpectedMetrics = `
# HELP connection_info Information about the connection
# TYPE connection_info gauge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import (

loki_fake "github.com/grafana/alloy/internal/component/common/loki/client/fake"
"github.com/prometheus/common/model"
"go.uber.org/goleak"

"github.com/DATA-DOG/go-sqlmock"
"github.com/go-kit/log"
"github.com/stretchr/testify/require"
)

func TestQuerySampleRun(t *testing.T) {
defer goleak.VerifyNone(t)

db, mock, err := sqlmock.New(sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual))
require.NoError(t, err)
defer db.Close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ import (
loki_fake "github.com/grafana/alloy/internal/component/common/loki/client/fake"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
)

func TestSchemaTableRun(t *testing.T) {
// The goroutine which deletes expired entries runs indefinitely,
// see https://github.com/hashicorp/golang-lru/blob/v2.0.7/expirable/expirable_lru.go#L79-L80
defer goleak.VerifyNone(t, goleak.IgnoreTopFunction("github.com/hashicorp/golang-lru/v2/expirable.NewLRU[...].func1"))

db, mock, err := sqlmock.New(sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual))
require.NoError(t, err)
defer db.Close()
Expand Down

0 comments on commit 335fb90

Please sign in to comment.