Skip to content

Commit

Permalink
BED-4526 chore: bootstrap graph db in migration test (#1181)
Browse files Browse the repository at this point in the history
  • Loading branch information
mistahj67 authored Feb 28, 2025
1 parent 651431f commit 69519fb
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/api/src/test/integration/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import (
"testing"

"github.com/specterops/bloodhound/cache"
schema "github.com/specterops/bloodhound/graphschema"
"github.com/specterops/bloodhound/src/auth"
"github.com/specterops/bloodhound/src/bootstrap"
"github.com/specterops/bloodhound/src/config"
"github.com/specterops/bloodhound/src/database"
"github.com/specterops/bloodhound/src/database/migration"
"github.com/specterops/bloodhound/src/test/integration/utils"
Expand Down Expand Up @@ -69,13 +72,24 @@ func Prepare(ctx context.Context, db database.Database) error {
return nil
}

func bootstrapGraphDb(ctx context.Context, cfg config.Configuration) error {
if graphDB, err := bootstrap.ConnectGraph(ctx, cfg); err != nil {
return fmt.Errorf("failed to connect graph database: %v", err)
} else {
defer graphDB.Close(ctx)
return bootstrap.MigrateGraph(ctx, graphDB, schema.DefaultGraphSchema())
}
}

func SetupTestMigrator(sources ...migration.Source) (*gorm.DB, *migration.Migrator, error) {
if cfg, err := utils.LoadIntegrationTestConfig(); err != nil {
return nil, nil, fmt.Errorf("failed to load integration test config: %w", err)
} else if db, err := gorm.Open(postgres.Open(cfg.Database.PostgreSQLConnectionString())); err != nil {
return nil, nil, fmt.Errorf("failed to open postgres connection: %w", err)
} else if err = wipeGormDB(db); err != nil {
return nil, nil, fmt.Errorf("failed to wipe database: %w", err)
} else if err := bootstrapGraphDb(context.Background(), cfg); err != nil {
return nil, nil, fmt.Errorf("failed to bootstrap graph db database: %w", err)
} else {
return db, &migration.Migrator{
Sources: sources,
Expand Down

0 comments on commit 69519fb

Please sign in to comment.