postgrestest

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package postgrestest provides real PostgreSQL containers for integration tests. It never substitutes a fake for PostgreSQL semantics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Image    string
	Database string
	Username string
	Password string
	// HostPort optionally binds PostgreSQL to a stable loopback port. It is
	// useful for stop/start tests whose client endpoint must not move.
	HostPort string
	// CleanupTimeout bounds container termination even when the setup context
	// has already been canceled.
	CleanupTimeout time.Duration
	Setup          func(context.Context, string) error
}

Config controls an isolated PostgreSQL container. Setup runs exactly once after PostgreSQL is accepting connections and receives its complete DSN.

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database owns a PostgreSQL test container and its connection string.

func Start

func Start(ctx context.Context, config Config) (*Database, error)

Start creates a PostgreSQL container, waits for readiness, obtains a DSN, and invokes the optional deterministic setup hook.

func (*Database) Close

func (d *Database) Close(ctx context.Context) error

Close terminates the container. Failed termination may be retried; after a successful termination, later calls return nil without repeating it.

func (*Database) Container

func (d *Database) Container() *postgres.PostgresContainer

Container exposes the native testcontainers PostgreSQL container.

func (*Database) DSN

func (d *Database) DSN() string

DSN returns the complete pgx-compatible connection string. Treat it as a secret because it contains the configured test credentials.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL