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

@ -8,9 +8,13 @@ import (
"npm/internal/logger"
"github.com/stretchr/testify/assert"
"go.uber.org/goleak"
)
func TestInit(t *testing.T) {
// goleak is used to detect goroutine leaks
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
t.Setenv("NPM_DATA_FOLDER", "/path/to/some/data/folder")
t.Setenv("NPM_LOG_LEVEL", "warn")
t.Setenv("NPM_DB_DRIVER", "postgres")
@ -45,6 +49,9 @@ func TestInit(t *testing.T) {
}
func TestConnectURLs(t *testing.T) {
// goleak is used to detect goroutine leaks
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
type want struct {
gorm string
dbmate string
@ -118,6 +125,9 @@ func TestConnectURLs(t *testing.T) {
}
func TestCreateDataFolders(t *testing.T) {
// goleak is used to detect goroutine leaks
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
t.Setenv("NPM_DATA_FOLDER", "/tmp/npmtest")
version := "777.777.777"

View File

@ -2,8 +2,9 @@ package config
import (
"fmt"
"npm/internal/logger"
"os"
"npm/internal/logger"
)
// CreateDataFolders will recursively create these folders within the

View File

@ -4,9 +4,13 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"go.uber.org/goleak"
)
func TestAcmeshGetWellknown(t *testing.T) {
// goleak is used to detect goroutine leaks
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
a := acmesh{
Home: "/data/.acme.sh",
}