Help us shape the future of Go! Take the 2026 Go Developer Survey

sqltest

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package sqltest runs a component test against a real postgres. See waffle/docs/conventions/component-harness.md.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DockerOption

type DockerOption func(*container)

func Container

func Container(name string) DockerOption

func Port

func Port(port int) DockerOption

func Runtime

func Runtime(binary string) DockerOption

For a machine with both docker and podman.

type MigrateFunc

type MigrateFunc func(ctx context.Context, handle *dbSql.DB) error

Taken as a function rather than driven from here, to keep goose out of the sql module's dependency graph, which every service carries.

type Option

type Option func(*Postgres)

func Database

func Database(name string) Option

Only needed alongside Docker — a DSN already carries the name.

func Docker

func Docker(image string, opts ...DockerOption) Option

Last resort, after Dsn and Env. Trust authentication, so no password exists to keep anywhere; a binary rather than testcontainers, to stay out of go.mod.

func Dsn

func Dsn(dsn string) Option

func Env

func Env(keys ...string) Option

First non-empty wins. There is no built-in default, because one carrying a password would put a credential in this repository.

func Ephemeral

func Ephemeral() Option

The process id in the name is what lets `go test ./...` run two packages at once. So the name in a DSN is not the name used.

func Migrations

func Migrations(migrate MigrateFunc) Option

func Suffix added in v1.9.0

func Suffix(suffix string) Option

Appended to the name however it was given, DSN included — Database alone is ignored there, and a second instance would land in the first one's database.

func Tables

func Tables(names ...string) Option

Without it the tables are discovered from the schema.

type Postgres

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

func New

func New(opts ...Option) *Postgres

func (*Postgres) Db

func (p *Postgres) Db() sql.Db

func (*Postgres) Down

func (p *Postgres) Down(ctx context.Context) error

The container, if one was started, is left running: starting it is the only part that costs anything, and the next run reuses it.

func (*Postgres) FailWith added in v1.11.0

func (p *Postgres) FailWith(err error)

Every Db handed out fails with err until Reset; nil reads as a refused connection.

func (*Postgres) Handle

func (p *Postgres) Handle() *dbSql.DB

func (*Postgres) Migrate

func (p *Postgres) Migrate(ctx context.Context) error

func (*Postgres) Name

func (p *Postgres) Name() string

func (*Postgres) Provision

func (p *Postgres) Provision(ctx context.Context) error

func (*Postgres) Reset

func (p *Postgres) Reset(ctx context.Context) error

Truncate rather than a held-open transaction: the scenario talks to the service over a real connection, and context values do not cross that.

Jump to

Keyboard shortcuts

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