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 PostgresDriver
- func (d *PostgresDriver) Driver() dbtestkit.Driver
- func (d *PostgresDriver) GenerateDump(ctx context.Context, env *dbtestkit.Environment, dumpPath string) error
- func (d *PostgresDriver) ResetStrategy() dbtestkit.ResetStrategy
- func (d *PostgresDriver) RestoreDump(ctx context.Context, env *dbtestkit.Environment, dumpPath string) error
- func (d *PostgresDriver) Start(ctx context.Context, env *dbtestkit.Environment) (string, error)
- func (d *PostgresDriver) Stop(ctx context.Context, _ *dbtestkit.Environment) error
- func (d *PostgresDriver) 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 PostgresDriver ¶ added in v0.3.2
type PostgresDriver struct {
// contains filtered or unexported fields
}
PostgresDriver implements dbtestkit.DatabaseDriver for PostgreSQL.
func (*PostgresDriver) Driver ¶ added in v0.3.2
func (d *PostgresDriver) Driver() dbtestkit.Driver
Driver returns the dbtestkit.Driver constant this implementation serves.
func (*PostgresDriver) GenerateDump ¶ added in v0.3.2
func (d *PostgresDriver) 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 (*PostgresDriver) ResetStrategy ¶ added in v0.3.2
func (d *PostgresDriver) ResetStrategy() dbtestkit.ResetStrategy
ResetStrategy returns RestoreDump to utilize the fast-path CLI pipe.
func (*PostgresDriver) RestoreDump ¶ added in v0.3.2
func (d *PostgresDriver) 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 (*PostgresDriver) Start ¶ added in v0.3.2
func (d *PostgresDriver) Start(ctx context.Context, env *dbtestkit.Environment) (string, error)
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)
func (*PostgresDriver) Stop ¶ added in v0.3.2
func (d *PostgresDriver) Stop(ctx context.Context, _ *dbtestkit.Environment) error
Stop terminates the container.
func (*PostgresDriver) Truncate ¶ added in v0.3.2
func (d *PostgresDriver) Truncate(_ context.Context, _ *dbtestkit.Environment) error
Truncate is a no-op for Postgres — the pristine dump's DROP ... IF EXISTS statements make truncation redundant on the fast path.