mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-06-18 18:16:26 +00:00
Add goleak in unit tests
This commit is contained in:
@ -8,9 +8,13 @@ import (
|
||||
"npm/internal/api/middleware"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/goleak"
|
||||
)
|
||||
|
||||
func TestAccessControl(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
|
@ -10,9 +10,13 @@ import (
|
||||
"npm/internal/api/middleware"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/goleak"
|
||||
)
|
||||
|
||||
func TestBodyContext(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
// Create a test request with a body
|
||||
body := []byte(`{"name": "John", "age": 30}`)
|
||||
req, err := http.NewRequest("POST", "/test", bytes.NewBuffer(body))
|
||||
|
@ -6,12 +6,16 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/goleak"
|
||||
|
||||
"npm/internal/api/middleware"
|
||||
"npm/internal/config"
|
||||
)
|
||||
|
||||
func TestEnforceSetup(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
shouldBeSetup bool
|
||||
|
@ -10,9 +10,13 @@ import (
|
||||
"npm/internal/api/middleware"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/goleak"
|
||||
)
|
||||
|
||||
func TestExpansion(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
t.Run("with expand query param", func(t *testing.T) {
|
||||
req, err := http.NewRequest("GET", "/path?expand=item1,item2", nil)
|
||||
assert.NoError(t, err)
|
||||
@ -47,6 +51,9 @@ func TestExpansion(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetExpandFromContext(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
t.Run("with context value", func(t *testing.T) {
|
||||
req, err := http.NewRequest("GET", "/path", nil)
|
||||
assert.NoError(t, err)
|
||||
|
@ -13,9 +13,13 @@ import (
|
||||
"npm/internal/tags"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/goleak"
|
||||
)
|
||||
|
||||
func TestListQuery(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
queryParams string
|
||||
@ -61,6 +65,9 @@ func TestListQuery(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetFiltersFromContext(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
req, err := http.NewRequest("GET", "/test", nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@ -75,6 +82,9 @@ func TestGetFiltersFromContext(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetSortFromContext(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
req, err := http.NewRequest("GET", "/test", nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
Reference in New Issue
Block a user