pgtest

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package pgtest starts an ephemeral Postgres for tests via Testcontainers. Import only from _test.go files so production binaries do not link the Docker SDK.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DatabaseName

func DatabaseName(tb testing.TB) string

DatabaseName turns tb.Name() into a Postgres identifier (≤63 chars).

Types

type Container

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

Container is a running Postgres (Testcontainers or DATABASE_* from the environment).

func Start

func Start(tb testing.TB, opts ...Option) *Container

Start is StartOrEnv: reuse DATABASE_* when DATABASE_HOST is set (CI sidecar), otherwise launch postgres:17 via Testcontainers.

func StartOrEnv

func StartOrEnv(tb testing.TB, opts ...Option) *Container

StartOrEnv uses DATABASE_* when DATABASE_HOST is set; otherwise starts a container.

func (*Container) Config

func (c *Container) Config() postgres.Config

Config returns connection settings for the test Postgres.

func (*Container) Connect

func (c *Container) Connect(tb testing.TB, database string, migrations fs.FS) *pgxpool.Pool

Connect bootstraps database (CREATE DATABASE + *.up.sql) via postgres.Connect. An empty database name becomes DatabaseName(tb). The pool is closed on tb.Cleanup.

type Option

type Option func(*options)

Option configures Start / StartOrEnv.

func WithImage

func WithImage(image string) Option

WithImage overrides the Postgres image (default postgres:17).

Jump to

Keyboard shortcuts

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