mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-22 22:59:09 +02:00
fix tests
This commit is contained in:
@@ -1230,9 +1230,9 @@ func (s *SqlStore) getAccount(ctx context.Context, accountID string) (*types.Acc
|
|||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, pgx.ErrNoRows) {
|
if errors.Is(err, pgx.ErrNoRows) {
|
||||||
return nil, errors.New("account not found")
|
return nil, status.NewAccountNotFoundError(accountID)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, status.NewGetAccountFromStoreError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = json.Unmarshal(networkNet, &account.Network.Net)
|
_ = json.Unmarshal(networkNet, &account.Network.Net)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import (
|
|||||||
networkTypes "github.com/netbirdio/netbird/management/server/networks/types"
|
networkTypes "github.com/netbirdio/netbird/management/server/networks/types"
|
||||||
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
nbpeer "github.com/netbirdio/netbird/management/server/peer"
|
||||||
"github.com/netbirdio/netbird/management/server/posture"
|
"github.com/netbirdio/netbird/management/server/posture"
|
||||||
|
"github.com/netbirdio/netbird/management/server/testutil"
|
||||||
"github.com/netbirdio/netbird/management/server/types"
|
"github.com/netbirdio/netbird/management/server/types"
|
||||||
"github.com/netbirdio/netbird/route"
|
"github.com/netbirdio/netbird/route"
|
||||||
"github.com/netbirdio/netbird/shared/management/status"
|
"github.com/netbirdio/netbird/shared/management/status"
|
||||||
@@ -242,8 +243,12 @@ func connectDBforTest(ctx context.Context, dsn string) (*pgxpool.Pool, error) {
|
|||||||
return pool, nil
|
return pool, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupBenchmarkDB(b testing.TB) (*SqlStore, string) {
|
func setupBenchmarkDB(b testing.TB) (*SqlStore, func(), string) {
|
||||||
dsn := "host=localhost user=postgres password=mysecretpassword dbname=testdb port=5432 sslmode=disable TimeZone=Europe/Berlin"
|
cleanup, dsn, err := testutil.CreatePostgresTestContainer()
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("failed to create test container: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatalf("failed to connect database: %v", err)
|
b.Fatalf("failed to connect database: %v", err)
|
||||||
@@ -484,11 +489,12 @@ func setupBenchmarkDB(b testing.TB) (*SqlStore, string) {
|
|||||||
b.Fatalf("create onboarding: %v", err)
|
b.Fatalf("create onboarding: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return store, accountID
|
return store, cleanup, accountID
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkGetAccount(b *testing.B) {
|
func BenchmarkGetAccount(b *testing.B) {
|
||||||
store, accountID := setupBenchmarkDB(b)
|
store, cleanup, accountID := setupBenchmarkDB(b)
|
||||||
|
defer cleanup()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
@@ -520,7 +526,8 @@ func BenchmarkGetAccount(b *testing.B) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAccountEquivalence(t *testing.T) {
|
func TestAccountEquivalence(t *testing.T) {
|
||||||
store, accountID := setupBenchmarkDB(t)
|
store, cleanup, accountID := setupBenchmarkDB(t)
|
||||||
|
defer cleanup()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
type getAccountFunc func(context.Context, string) (*types.Account, error)
|
type getAccountFunc func(context.Context, string) (*types.Account, error)
|
||||||
|
|||||||
Reference in New Issue
Block a user