Skip to content

Commit

Permalink
1. Fixed t.Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
maranqz committed Feb 4, 2024
1 parent bdef678 commit 970c136
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/test/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

package test

// Cleanup skipped for go1.13 and lower.
func Cleanup(t *testing.T, fn func()) {

Check failure on line 7 in internal/test/cleanup.go

View workflow job for this annotation

GitHub Actions / tests-units (1.13, ubuntu-latest)

undefined: testing
}
2 changes: 2 additions & 0 deletions internal/test/cleanup_go1.14.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"testing"
)

// Cleanup is a helper function to register cleanup function for a test.
// t.Cleanup was added in go1.14.
func Cleanup(t *testing.T, fn func()) {
t.Cleanup(fn)
}
2 changes: 1 addition & 1 deletion internal/test/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewDBMockWithClose(t *testing.T) (*sql.DB, sqlmock.Sqlmock) {
db, dbmock := NewDBMock()

// need to solve goroutine leak detection https://kumakichi.github.io/goroutine-leak.html
t.Cleanup(func() {
Cleanup(t, func() {
dbmock.ExpectClose()

require.NoError(t, db.Close())
Expand Down

0 comments on commit 970c136

Please sign in to comment.