Skip to content

Commit

Permalink
Simplify method signature.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelosalloum committed Apr 22, 2024
1 parent 005beff commit 53db3a2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
2 changes: 1 addition & 1 deletion cmd/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func Test_persistentPostRun(t *testing.T) {

ctx := context.Background()

adminDBConnectionPool := prepareAdminDBConnectionPool(t, ctx, dbt, true)
adminDBConnectionPool := prepareAdminDBConnectionPool(t, ctx, dbt.DSN)
defer adminDBConnectionPool.Close()

tenant.PrepareDBForTenant(t, dbt, tenantName)
Expand Down
23 changes: 10 additions & 13 deletions cmd/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
migrate "github.com/rubenv/sql-migrate"
"github.com/stellar/go/keypair"
"github.com/stellar/go/network"
supportDBTest "github.com/stellar/go/support/db/dbtest"
"github.com/stellar/go/support/log"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -24,20 +23,18 @@ import (
"github.com/stellar/stellar-disbursement-platform-backend/stellar-multitenant/pkg/tenant"
)

func prepareAdminDBConnectionPool(t *testing.T, ctx context.Context, dbt *supportDBTest.DB, withMigrations bool) db.DBConnectionPool {
func prepareAdminDBConnectionPool(t *testing.T, ctx context.Context, dbDSN string) db.DBConnectionPool {
t.Helper()

adminDatabaseDNS, err := router.GetDNSForAdmin(dbt.DSN)
adminDatabaseDNS, err := router.GetDNSForAdmin(dbDSN)
require.NoError(t, err)

if withMigrations {
var manager *cmdDB.SchemaMigrationManager
manager, err = cmdDB.NewSchemaMigrationManager(migrations.AdminMigrationRouter, router.AdminSchemaName, adminDatabaseDNS)
require.NoError(t, err)
defer manager.Close()
err = manager.OrchestrateSchemaMigrations(ctx, migrate.Up, 0)
require.NoError(t, err)
}
var manager *cmdDB.SchemaMigrationManager
manager, err = cmdDB.NewSchemaMigrationManager(migrations.AdminMigrationRouter, router.AdminSchemaName, adminDatabaseDNS)
require.NoError(t, err)
defer manager.Close()
err = manager.OrchestrateSchemaMigrations(ctx, migrate.Up, 0)
require.NoError(t, err)

adminDBConnectionPool, err := db.OpenDBConnectionPool(adminDatabaseDNS)
require.NoError(t, err)
Expand Down Expand Up @@ -143,7 +140,7 @@ func Test_DatabaseCommand_db_sdp_migrate(t *testing.T) {

ctx := context.Background()

adminDBConnectionPool := prepareAdminDBConnectionPool(t, ctx, dbt, true)
adminDBConnectionPool := prepareAdminDBConnectionPool(t, ctx, dbt.DSN)
defer adminDBConnectionPool.Close()

m := tenant.NewManager(tenant.WithDatabase(adminDBConnectionPool))
Expand Down Expand Up @@ -454,7 +451,7 @@ func Test_DatabaseCommand_db_setup_for_network(t *testing.T) {

ctx := context.Background()

adminDBConnectionPool := prepareAdminDBConnectionPool(t, ctx, dbt, true)
adminDBConnectionPool := prepareAdminDBConnectionPool(t, ctx, dbt.DSN)
defer adminDBConnectionPool.Close()

m := tenant.NewManager(tenant.WithDatabase(adminDBConnectionPool))
Expand Down
4 changes: 2 additions & 2 deletions db/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func Test_getDSNWithFixedSchema(t *testing.T) {
}

func Test_preExistingSchemasGetOverwritten(t *testing.T) {
dsnWithoutSearchPath := "postgres://user:password@localhost:5432/test"
dsnWithSearchPath := "postgres://user:password@localhost:5432/test?search_path=old"
dsnWithoutSearchPath := "postgres://user:password@somehost:5432/test"
dsnWithSearchPath := "postgres://user:password@somehost:5432/test?search_path=old"

testCases := []struct {
name string
Expand Down
22 changes: 9 additions & 13 deletions stellar-auth/pkg/cli/add_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/lib/pq"
migrate "github.com/rubenv/sql-migrate"
"github.com/spf13/cobra"
supportDBTest "github.com/stellar/go/support/db/dbtest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand All @@ -30,20 +29,17 @@ func (m *PasswordPromptMock) Run() (string, error) {

var _ PasswordPromptInterface = (*PasswordPromptMock)(nil)

func prepareAdminDBConnectionPool(t *testing.T, ctx context.Context, dbt *supportDBTest.DB, withMigrations bool) db.DBConnectionPool {
func prepareAdminDBConnectionPool(t *testing.T, ctx context.Context, dbDSN string) db.DBConnectionPool {
t.Helper()

adminDatabaseDNS, err := router.GetDNSForAdmin(dbt.DSN)
adminDatabaseDNS, err := router.GetDNSForAdmin(dbDSN)
require.NoError(t, err)

if withMigrations {
var manager *cmdDB.SchemaMigrationManager
manager, err = cmdDB.NewSchemaMigrationManager(migrations.AdminMigrationRouter, router.AdminSchemaName, adminDatabaseDNS)
require.NoError(t, err)
defer manager.Close()
err = manager.OrchestrateSchemaMigrations(ctx, migrate.Up, 0)
require.NoError(t, err)
}
manager, err := cmdDB.NewSchemaMigrationManager(migrations.AdminMigrationRouter, router.AdminSchemaName, adminDatabaseDNS)
require.NoError(t, err)
defer manager.Close()
err = manager.OrchestrateSchemaMigrations(ctx, migrate.Up, 0)
require.NoError(t, err)

adminDBConnectionPool, err := db.OpenDBConnectionPool(adminDatabaseDNS)
require.NoError(t, err)
Expand All @@ -58,7 +54,7 @@ func Test_authAddUserCommand(t *testing.T) {

ctx := context.Background()

adminDBConnectionPool := prepareAdminDBConnectionPool(t, ctx, dbt, true)
adminDBConnectionPool := prepareAdminDBConnectionPool(t, ctx, dbt.DSN)
defer adminDBConnectionPool.Close()

tDSN := tenant.PrepareDBForTenant(t, dbt, tenantName)
Expand Down Expand Up @@ -225,7 +221,7 @@ func Test_execAddUserFunc(t *testing.T) {

ctx := context.Background()

adminDBConnectionPool := prepareAdminDBConnectionPool(t, ctx, dbt, true)
adminDBConnectionPool := prepareAdminDBConnectionPool(t, ctx, dbt.DSN)
defer adminDBConnectionPool.Close()

tDSN := tenant.PrepareDBForTenant(t, dbt, tenantName)
Expand Down

0 comments on commit 53db3a2

Please sign in to comment.