diff --git a/cmd/ftl-proxy-pg/main.go b/cmd/ftl-proxy-pg/main.go index 81e2eeee8f..1bf84fbd51 100644 --- a/cmd/ftl-proxy-pg/main.go +++ b/cmd/ftl-proxy-pg/main.go @@ -39,7 +39,7 @@ func main() { kctx.FatalIfErrorf(err, "failed to initialize observability") proxy := pgproxy.New(cli.Config.Listen, func(ctx context.Context, params map[string]string) (string, error) { - return "postgres://127.0.0.1:15432/database_testdb?sslmode=disable&user=postgres&password=secret", nil + return "postgres://localhost:5432/postgres?user=" + params["user"], nil }) if err := proxy.Start(ctx, nil); err != nil { kctx.FatalIfErrorf(err, "failed to start proxy") diff --git a/go-runtime/server/database.go b/go-runtime/server/database.go index 4238e925af..b8f0415aa5 100644 --- a/go-runtime/server/database.go +++ b/go-runtime/server/database.go @@ -4,7 +4,6 @@ import ( "context" "database/sql" "fmt" - "os" "reflect" "time" @@ -48,18 +47,10 @@ func InitDatabase(ref reflection.Ref, dbtype string, protoDBtype modulecontext.D DBType: dbtype, DB: once.Once(func(ctx context.Context) (*sql.DB, error) { logger := log.FromContext(ctx) - var dsn string provider := modulecontext.FromContext(ctx).CurrentContext() - d, _, err := provider.GetDatabase(ref.Name, protoDBtype) + dsn, testDb, err := provider.GetDatabase(ref.Name, protoDBtype) if err != nil { - if protoDBtype == modulecontext.DBTypePostgres { - proxyAddress := os.Getenv("PG_PROXY_ADDRESS") - dsn = "postgres://" + proxyAddress + "/" + ref.Name - } else { - return nil, fmt.Errorf("failed to get database %q: %w", ref.Name, err) - } - } else { - dsn = d + return nil, fmt.Errorf("failed to get database %q: %w", ref.Name, err) } logger.Debugf("Opening database: %s", ref.Name) @@ -79,7 +70,7 @@ func InitDatabase(ref reflection.Ref, dbtype string, protoDBtype modulecontext.D return nil, fmt.Errorf("failed to register database metrics: %w", err) } db.SetConnMaxIdleTime(time.Minute) - if os.Getenv("FTL_INTEGRATION_TEST") == "true" { + if testDb { // In tests we always close the connections, as the DB being clean might invalidate pooled connections db.SetMaxIdleConns(0) } else { diff --git a/internal/integration/harness.go b/internal/integration/harness.go index 5c97ae0f2c..2dde020f5b 100644 --- a/internal/integration/harness.go +++ b/internal/integration/harness.go @@ -218,7 +218,6 @@ func run(t *testing.T, actionsOrOptions ...ActionOrOption) { for key, value := range opts.envars { t.Setenv(key, value) } - t.Setenv("FTL_INTEGRATION_TEST", "true") cwd, err := os.Getwd() assert.NoError(t, err) diff --git a/internal/modulecontext/module_context.go b/internal/modulecontext/module_context.go index ef1e91144c..6327f1fe8c 100644 --- a/internal/modulecontext/module_context.go +++ b/internal/modulecontext/module_context.go @@ -159,6 +159,7 @@ func (m ModuleContext) GetSecret(name string, value any) error { // if the database is not a test database. func (m ModuleContext) GetDatabase(name string, dbType DBType) (string, bool, error) { db, ok := m.databases[name] + // TODO: Remove databases from the context once we have a way to inject test dbs in some other way if !ok { if dbType == DBTypePostgres { proxyAddress := os.Getenv("PG_PROXY_ADDRESS")