mirror of
https://github.com/hanzo-fi/go-libs.git
synced 2026-10-30 20:53:44 +00:00
32 lines
1.1 KiB
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
|
|
})
|
|
}
|