Documentation
¶
Overview ¶
Package postgres provides PostgreSQL container management for testing.
Index ¶
- func Container(ctx context.Context, opts ...Option) (*postgres.PostgresContainer, error)
- func MustNew(ctx context.Context) (*sql.DB, func())
- func MustNewWithOptions(ctx context.Context, opts ...Option) (*sql.DB, func())
- func New(ctx context.Context) (*sql.DB, func(), error)
- func NewWithConfig(ctx context.Context, cfg *config.PostgresConfig) (*sql.DB, func(), error)
- func NewWithOptions(ctx context.Context, opts ...Option) (*sql.DB, func(), error)
- type Option
- func WithDatabase(database string) Option
- func WithHealthCheckInterval(interval time.Duration) Option
- func WithHealthCheckRetry(retries int) Option
- func WithHealthCheckTimeout(timeout time.Duration) Option
- func WithImage(image string) Option
- func WithPassword(password string) Option
- func WithPoolSettings(maxOpen, maxIdle int, maxLifetime time.Duration) Option
- func WithUsername(username string) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Container ¶
Container exposes the underlying testcontainers PostgreSQL module for advanced use.
func MustNew ¶
MustNew starts a PostgreSQL container and panics on error. Use for tests where you want quick setup.
func MustNewWithOptions ¶
MustNewWithOptions starts a PostgreSQL container with options and panics on error.
func New ¶
New starts a new PostgreSQL container and returns a connected *sql.DB. Call the returned cleanup function to stop and remove the container.
Example:
ctx := context.Background()
db, cleanup, err := postgres.New(ctx)
if err != nil {
panic(err)
}
defer cleanup()
func NewWithConfig ¶
NewWithConfig starts a PostgreSQL container with custom configuration.
Types ¶
type Option ¶
type Option func(*config.PostgresConfig)
Option configures PostgreSQL container options.
func WithDatabase ¶
WithDatabase sets the PostgreSQL database name.
func WithHealthCheckInterval ¶
WithHealthCheckInterval configures the interval between health check retries.
func WithHealthCheckRetry ¶
WithHealthCheckRetry configures health check retry attempts.
func WithHealthCheckTimeout ¶
WithHealthCheckTimeout sets the health check timeout duration.
func WithPassword ¶
WithPassword sets the PostgreSQL password.
func WithPoolSettings ¶
WithPoolSettings configures the connection pool.
func WithUsername ¶
WithUsername sets the PostgreSQL username.