testutils

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0, MIT Imports: 19 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 DecodeData

func DecodeData(t testing.TB, w *httptest.ResponseRecorder) map[string]any

DecodeData parses the envelope and returns the data object.

func Do

func Do(t testing.TB, r http.Handler, method, path, body string) *httptest.ResponseRecorder

Do sends one request with an optional JSON body and returns the recorder. An empty body sends no body at all.

func DoForm

func DoForm(t testing.TB, r http.Handler, method, path string, values url.Values) *httptest.ResponseRecorder

DoForm sends one form-encoded request (OAuth/OIDC endpoints).

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.

func WithAdminHeader

func WithAdminHeader(req *http.Request) *http.Request

WithAdminHeader marks a request for the stub admin guard used by handler tests.

func WithCookie

func WithCookie(req *http.Request, name, token string) *http.Request

WithCookie attaches the session cookie to a request. Cookie attributes govern storage on the server response side and are meaningless for an outgoing client header.

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 Envelope

type Envelope struct {
	Status   string          `json:"status"`
	Message  string          `json:"message"`
	Data     json.RawMessage `json:"data"`
	Error    json.RawMessage `json:"error"`
	Metadata struct {
		StatusCode int    `json:"status_code"`
		RequestID  string `json:"request_id"`
	} `json:"metadata"`
}

Envelope is the standard response envelope shape.

func DecodeEnvelope

func DecodeEnvelope(t testing.TB, w *httptest.ResponseRecorder) Envelope

DecodeEnvelope parses the standard response envelope.

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