Add goleak in unit tests

This commit is contained in:
Jamie Curnow
2023-11-08 09:57:15 +10:00
parent 689bcb0077
commit 6da020aab1
41 changed files with 371 additions and 8 deletions

View File

@ -4,9 +4,13 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"go.uber.org/goleak"
)
func TestFindItemInInterface(t *testing.T) {
// goleak is used to detect goroutine leaks
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
obj := map[string]interface{}{
"key1": "value1",
"key2": 10,

View File

@ -4,6 +4,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"go.uber.org/goleak"
)
type rect struct {
@ -12,6 +13,9 @@ type rect struct {
}
func TestMapContainsKey(t *testing.T) {
// goleak is used to detect goroutine leaks
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
var r rect
r.width = 5
r.height = 5

View File

@ -5,9 +5,13 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"go.uber.org/goleak"
)
func TestSliceContainsItem(t *testing.T) {
// goleak is used to detect goroutine leaks
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
type want struct {
result bool
}

View File

@ -4,9 +4,13 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"go.uber.org/goleak"
)
func TestCleanupWhitespace(t *testing.T) {
// goleak is used to detect goroutine leaks
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
tests := []struct {
name string
input string
@ -51,6 +55,9 @@ upstream npm_upstream_5 {
}
func TestPrettyPrintJSON(t *testing.T) {
// goleak is used to detect goroutine leaks
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
testCases := []struct {
input string
expected string

View File

@ -4,9 +4,13 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"go.uber.org/goleak"
)
func TestUnixMilliToNiceFormat(t *testing.T) {
// goleak is used to detect goroutine leaks
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
tests := []struct {
input int64
expected string