mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-06-18 10:06:26 +00:00
Add goleak in unit tests
This commit is contained in:
@ -4,9 +4,14 @@ import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go.uber.org/goleak"
|
||||
)
|
||||
|
||||
func TestDBDate_Value(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
// Create a DBDate instance with a specific time
|
||||
expectedTime := time.Date(2022, time.January, 1, 0, 0, 0, 0, time.UTC)
|
||||
dbDate := DBDate{Time: expectedTime}
|
||||
@ -32,6 +37,9 @@ func TestDBDate_Value(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDBDate_Scan(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
// Simulate a value from the database (unix timestamp)
|
||||
unixTime := int64(1640995200)
|
||||
|
||||
@ -56,6 +64,9 @@ func TestDBDate_Scan(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDBDate_UnmarshalJSON(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
// Simulate a JSON input representing a unix timestamp
|
||||
jsonData := []byte("1640995200")
|
||||
|
||||
@ -81,6 +92,9 @@ func TestDBDate_UnmarshalJSON(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDBDate_MarshalJSON(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
// Create a DBDate instance with a specific time
|
||||
expectedTime := time.Date(2022, time.January, 1, 0, 0, 0, 0, time.UTC)
|
||||
dbDate := DBDate{Time: expectedTime}
|
||||
|
@ -2,9 +2,14 @@ package types
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"go.uber.org/goleak"
|
||||
)
|
||||
|
||||
func TestNullableDBIntValue(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
var d NullableDBInt
|
||||
|
||||
// Test when Int is 0 (null)
|
||||
@ -23,6 +28,9 @@ func TestNullableDBIntValue(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNullableDBIntScan(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
var d NullableDBInt
|
||||
|
||||
// Test when src is an int
|
||||
@ -57,6 +65,9 @@ func TestNullableDBIntScan(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNullableDBIntUnmarshalJSON(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
var d NullableDBInt
|
||||
|
||||
// Test when data is an integer value
|
||||
@ -73,6 +84,9 @@ func TestNullableDBIntUnmarshalJSON(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNullableDBIntMarshalJSON(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
var d NullableDBInt
|
||||
|
||||
// Test when Int is 0 (null)
|
||||
|
@ -3,9 +3,14 @@ package types
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"testing"
|
||||
|
||||
"go.uber.org/goleak"
|
||||
)
|
||||
|
||||
func TestNullableDBUint_Value(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 NullableDBUint
|
||||
@ -40,6 +45,9 @@ func TestNullableDBUint_Value(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNullableDBUint_Scan(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 interface{}
|
||||
@ -76,6 +84,9 @@ func TestNullableDBUint_Scan(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNullableDBUint_UnmarshalJSON(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 []byte
|
||||
@ -112,6 +123,9 @@ func TestNullableDBUint_UnmarshalJSON(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNullableDBUint_MarshalJSON(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 NullableDBUint
|
||||
|
@ -3,10 +3,15 @@ package types
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go.uber.org/goleak"
|
||||
)
|
||||
|
||||
// TestNullableDBDateValue tests the Value method of the NullableDBDate type
|
||||
func TestNullableDBDateValue(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
tme := time.Date(2022, time.January, 1, 0, 0, 0, 0, time.UTC)
|
||||
d := NullableDBDate{
|
||||
Time: &tme,
|
||||
@ -26,6 +31,9 @@ func TestNullableDBDateValue(t *testing.T) {
|
||||
|
||||
// TestNullableDBDateScan tests the Scan method of the NullableDBDate type
|
||||
func TestNullableDBDateScan(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
var d NullableDBDate
|
||||
|
||||
err := d.Scan(int64(1640995200))
|
||||
@ -42,6 +50,9 @@ func TestNullableDBDateScan(t *testing.T) {
|
||||
|
||||
// TestNullableDBDateUnmarshalJSON tests the UnmarshalJSON method of the NullableDBDate type
|
||||
func TestNullableDBDateUnmarshalJSON(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
data := []byte(`1640995200`)
|
||||
var d NullableDBDate
|
||||
|
||||
@ -59,6 +70,9 @@ func TestNullableDBDateUnmarshalJSON(t *testing.T) {
|
||||
|
||||
// TestNullableDBDateMarshalJSON tests the MarshalJSON method of the NullableDBDate type
|
||||
func TestNullableDBDateMarshalJSON(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
tme := time.Date(2022, time.January, 1, 0, 0, 0, 0, time.UTC)
|
||||
d := NullableDBDate{
|
||||
Time: &tme,
|
||||
@ -78,6 +92,9 @@ func TestNullableDBDateMarshalJSON(t *testing.T) {
|
||||
|
||||
// TestNullableDBDateAsInt64 tests the AsInt64 method of the NullableDBDate type
|
||||
func TestNullableDBDateAsInt64(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
tme := time.Date(2022, time.January, 1, 0, 0, 0, 0, time.UTC)
|
||||
d := NullableDBDate{
|
||||
Time: &tme,
|
||||
@ -93,6 +110,9 @@ func TestNullableDBDateAsInt64(t *testing.T) {
|
||||
|
||||
// TestNullableDBDateAsString tests the AsString method of the NullableDBDate type
|
||||
func TestNullableDBDateAsString(t *testing.T) {
|
||||
// goleak is used to detect goroutine leaks
|
||||
defer goleak.VerifyNone(t, goleak.IgnoreAnyFunction("database/sql.(*DB).connectionOpener"))
|
||||
|
||||
tme := time.Date(2022, time.January, 1, 0, 0, 0, 0, time.UTC)
|
||||
d := NullableDBDate{
|
||||
Time: &tme,
|
||||
|
Reference in New Issue
Block a user