Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jvmakine committed Nov 25, 2024
1 parent 4944b90 commit b635b09
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cmd/ftl-proxy-pg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
15 changes: 3 additions & 12 deletions go-runtime/server/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"database/sql"
"fmt"
"os"
"reflect"
"time"

Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion internal/integration/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions internal/modulecontext/module_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit b635b09

Please sign in to comment.