Documentation
¶
Overview ¶
Package postgres. postgres.go - PostgreSQL backend for dbtestkit. Boots a Postgres test container via testcontainers-go, using tmpfs for the data directory and a tuned configuration for fast test execution.
Index ¶
- func New() dbtestkit.DatabaseDriver
- type Driver
- func (d *Driver) Driver() dbtestkit.Driver
- func (d *Driver) GenerateDump(ctx context.Context, env *dbtestkit.Environment, dumpPath string) error
- func (d *Driver) RestoreDump(ctx context.Context, env *dbtestkit.Environment, dumpPath string) error
- func (d *Driver) Start(ctx context.Context, env *dbtestkit.Environment) (string, error)
- func (d *Driver) Stop(ctx context.Context, _ *dbtestkit.Environment) error
- func (d *Driver) Truncate(_ context.Context, _ *dbtestkit.Environment) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New() dbtestkit.DatabaseDriver
New returns a fresh Postgres driver instance.
Pass the result to dbtestkit.WithDriver:
dbtestkit.Run(m,
dbtestkit.WithDriver(postgres.New()),
...
)
Types ¶
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver implements dbtestkit.DatabaseDriver for PostgreSQL.
func (*Driver) GenerateDump ¶
func (d *Driver) GenerateDump(ctx context.Context, env *dbtestkit.Environment, dumpPath string) error
GenerateDump writes a fresh pristine dump to dumpPath via pg_dump.
Uses --clean --if-exists so the dump contains DROP TABLE IF EXISTS equivalents (DROP ... IF EXISTS), making restores idempotent without requiring a separate TRUNCATE pass.
func (*Driver) RestoreDump ¶
func (d *Driver) RestoreDump(ctx context.Context, env *dbtestkit.Environment, dumpPath string) error
RestoreDump pipes the pristine SQL dump into psql inside the container. This is the fast-path reset (~ms).
func (*Driver) Start ¶
Start boots the Postgres container and returns the DSN.
The container is configured with:
- tmpfs at /var/lib/postgresql/data for in-memory storage
- a wait strategy that polls the postgres CLI until the server responds
- the standard postgres initdb flow (database + user created from POSTGRES_DB / POSTGRES_USER / POSTGRES_PASSWORD env vars)