diff --git a/pkg/testutils/util.go b/pkg/testutils/util.go index d4d47f900..12836fe3c 100644 --- a/pkg/testutils/util.go +++ b/pkg/testutils/util.go @@ -113,72 +113,6 @@ func WithStateAndConnectionToContainer(t *testing.T, fn func(*state.State, *sql. fn(st, db) } -func WithMigratorAndConnectionToContainer(t *testing.T, fn func(mig *roll.Roll, db *sql.DB)) { - t.Helper() - ctx := context.Background() - - tDB, err := sql.Open("postgres", tConnStr) - if err != nil { - t.Fatal(err) - } - - t.Cleanup(func() { - if err := tDB.Close(); err != nil { - t.Fatalf("Failed to close database connection: %v", err) - } - }) - - dbName := randomDBName() - - _, err = tDB.ExecContext(ctx, fmt.Sprintf("CREATE DATABASE %s", pq.QuoteIdentifier(dbName))) - if err != nil { - t.Fatal(err) - } - - u, err := url.Parse(tConnStr) - if err != nil { - t.Fatal(err) - } - - u.Path = "/" + dbName - connStr := u.String() - - st, err := state.New(ctx, connStr, "pgroll") - if err != nil { - t.Fatal(err) - } - - err = st.Init(ctx) - if err != nil { - t.Fatal(err) - } - - const lockTimeoutMs = 500 - mig, err := roll.New(ctx, connStr, "public", lockTimeoutMs, st) - if err != nil { - t.Fatal(err) - } - - t.Cleanup(func() { - if err := mig.Close(); err != nil { - t.Fatalf("Failed to close migrator connection: %v", err) - } - }) - - db, err := sql.Open("postgres", connStr) - if err != nil { - t.Fatal(err) - } - - t.Cleanup(func() { - if err := db.Close(); err != nil { - t.Fatalf("Failed to close database connection: %v", err) - } - }) - - fn(mig, db) -} - func WithMigratorInSchemaWithLockTimeoutAndConnectionToContainer(t *testing.T, schema string, lockTimeoutMs int, fn func(mig *roll.Roll, db *sql.DB)) { t.Helper() ctx := context.Background() @@ -252,3 +186,7 @@ func WithMigratorInSchemaWithLockTimeoutAndConnectionToContainer(t *testing.T, s func WithMigratorInSchemaAndConnectionToContainer(t *testing.T, schema string, fn func(mig *roll.Roll, db *sql.DB)) { WithMigratorInSchemaWithLockTimeoutAndConnectionToContainer(t, schema, 500, fn) } + +func WithMigratorAndConnectionToContainer(t *testing.T, fn func(mig *roll.Roll, db *sql.DB)) { + WithMigratorInSchemaWithLockTimeoutAndConnectionToContainer(t, "public", 500, fn) +}