postgres

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 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 Driver

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

Driver implements dbtestkit.DatabaseDriver for PostgreSQL.

func (*Driver) Driver

func (d *Driver) Driver() dbtestkit.Driver

Driver returns the dbtestkit.Driver constant this implementation serves.

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

func (d *Driver) 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 (*Driver) Stop

func (d *Driver) Stop(ctx context.Context, _ *dbtestkit.Environment) error

Stop terminates the container.

func (*Driver) Truncate

func (d *Driver) 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.

Jump to

Keyboard shortcuts

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