postgres

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 10 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

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

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

Stop terminates the container.

func (*PostgresDriver) Truncate added in v0.3.2

Truncate is a no-op for Postgres — the pristine dump's DROP ... IF EXISTS statements make truncation redundant on the fast path.

Jump to

Keyboard shortcuts

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