fix tests

This commit is contained in:
crn4
2025-10-31 15:46:16 +01:00
parent 435a342a36
commit ee7bda446d
2 changed files with 14 additions and 7 deletions

View File

@@ -1230,9 +1230,9 @@ func (s *SqlStore) getAccount(ctx context.Context, accountID string) (*types.Acc
)
if err != nil {
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)

View File

@@ -25,6 +25,7 @@ import (
networkTypes "github.com/netbirdio/netbird/management/server/networks/types"
nbpeer "github.com/netbirdio/netbird/management/server/peer"
"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/route"
"github.com/netbirdio/netbird/shared/management/status"
@@ -242,8 +243,12 @@ func connectDBforTest(ctx context.Context, dsn string) (*pgxpool.Pool, error) {
return pool, nil
}
func setupBenchmarkDB(b testing.TB) (*SqlStore, string) {
dsn := "host=localhost user=postgres password=mysecretpassword dbname=testdb port=5432 sslmode=disable TimeZone=Europe/Berlin"
func setupBenchmarkDB(b testing.TB) (*SqlStore, func(), string) {
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{})
if err != nil {
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)
}
return store, accountID
return store, cleanup, accountID
}
func BenchmarkGetAccount(b *testing.B) {
store, accountID := setupBenchmarkDB(b)
store, cleanup, accountID := setupBenchmarkDB(b)
defer cleanup()
ctx := context.Background()
b.ResetTimer()
b.ReportAllocs()
@@ -520,7 +526,8 @@ func BenchmarkGetAccount(b *testing.B) {
}
func TestAccountEquivalence(t *testing.T) {
store, accountID := setupBenchmarkDB(t)
store, cleanup, accountID := setupBenchmarkDB(t)
defer cleanup()
ctx := context.Background()
type getAccountFunc func(context.Context, string) (*types.Account, error)