Files
go-libs/pkg/testing/testservice/instrumentation_postgres.go

32 lines
1.1 KiB
Go

package testservice
import (
"context"
"fmt"
bunconnect "github.com/hanzo-fi/go-libs/v5/pkg/storage/bun/connect"
"github.com/hanzo-fi/go-libs/v5/pkg/testing/deferred"
)
func PostgresInstrumentation(postgresConfiguration *deferred.Deferred[bunconnect.ConnectionOptions]) Instrumentation {
return InstrumentationFunc(func(ctx context.Context, cfg *RunConfiguration) error {
postgresConfiguration, err := postgresConfiguration.Wait(ctx)
if err != nil {
return err
}
cfg.AppendArgs("--"+bunconnect.PostgresURIFlag, postgresConfiguration.DatabaseSourceName)
if postgresConfiguration.MaxIdleConns != 0 {
cfg.AppendArgs("--"+bunconnect.PostgresMaxIdleConnsFlag, fmt.Sprint(postgresConfiguration.MaxIdleConns))
}
if postgresConfiguration.MaxOpenConns != 0 {
cfg.AppendArgs("--"+bunconnect.PostgresMaxOpenConnsFlag, fmt.Sprint(postgresConfiguration.MaxOpenConns))
}
if postgresConfiguration.ConnMaxIdleTime != 0 {
cfg.AppendArgs("--"+bunconnect.PostgresConnMaxIdleTimeFlag, fmt.Sprint(postgresConfiguration.ConnMaxIdleTime))
}
return nil
})
}