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

testutils

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: Apache-2.0, MIT Imports: 13 Imported by: 0

Documentation

Overview

Package testutils provides shared integration-test helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SkipWithoutDocker

func SkipWithoutDocker(t testing.TB)

SkipWithoutDocker skips the test when no healthy Docker provider is available. This lets container-based integration tests skip on hosts without a daemon — e.g. GitHub-hosted macOS runners, which lack nested virtualization and cannot run a Linux VM for Docker. It mirrors testcontainers.SkipIfProviderIsNotHealthy but accepts testing.TB.

Types

type ContainerExecutor

type ContainerExecutor struct {
	PG *Postgres
}

ContainerExecutor runs the PostgreSQL client tools inside the test Postgres container. It structurally satisfies database.Executor, so tests can override database.DefaultExecutor without an import cycle.

Host/port flags are stripped so the tools connect over the container-local Unix socket (trusted auth); env is ignored for the same reason. Files cross the boundary via container copy.

func (*ContainerExecutor) PGDump

func (e *ContainerExecutor) PGDump(ctx context.Context, _ []string, args []string, outputPath string) error

PGDump dumps to a path inside the container, then copies the file to the host output path.

func (*ContainerExecutor) PGRestore

func (e *ContainerExecutor) PGRestore(ctx context.Context, _ []string, args []string) error

PGRestore copies the dump file (the last argument) into the container, then restores from it.

func (*ContainerExecutor) PSQL

func (e *ContainerExecutor) PSQL(ctx context.Context, _ []string, args []string) error

PSQL copies the SQL file (the value of -f) into the container, then runs psql against it.

type Mailpit

type Mailpit struct {
	// SMTPAddr is the host:port of the SMTP listener.
	SMTPAddr string

	// APIURL is the HTTP API base URL (http://host:port).
	APIURL string

	// Username and Password are the relay credentials.
	Username string
	Password string
}

Mailpit is a running Mailpit container.

func StartMailpit

func StartMailpit(ctx context.Context, t testing.TB) *Mailpit

StartMailpit returns the shared Mailpit container for the test binary.

type MinIO

type MinIO struct {
	// Endpoint is the S3 API address (http://host:port).
	Endpoint string

	// AccessKey and Secret are the root credentials.
	AccessKey string
	Secret    string
}

MinIO is a running S3-compatible object store container.

func StartMinIO

func StartMinIO(ctx context.Context, t testing.TB) *MinIO

StartMinIO returns the shared object store container for the test binary.

type Postgres

type Postgres struct {
	// DSN is the connection string of the shared instance.
	DSN string
	// contains filtered or unexported fields
}

Postgres is a running Postgres container for integration tests.

func StartPostgres

func StartPostgres(ctx context.Context, t testing.TB) *Postgres

StartPostgres returns the shared Postgres container for the test binary.

func (*Postgres) ContainerID

func (p *Postgres) ContainerID() string

ContainerID returns the container ID for debugging.

func (*Postgres) CopyFileFromContainer

func (p *Postgres) CopyFileFromContainer(ctx context.Context, containerPath, hostPath string) error

CopyFileFromContainer copies a file from the container to the host.

func (*Postgres) CopyFileToContainer

func (p *Postgres) CopyFileToContainer(ctx context.Context, hostPath, containerPath string) error

CopyFileToContainer copies a file from host to container.

func (*Postgres) Exec

func (p *Postgres) Exec(ctx context.Context, cmd []string) (int, string, error)

Exec runs a command inside the Postgres container and returns the exit code and combined output. The command runs as the postgres user.

Jump to

Keyboard shortcuts

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