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

testutil

package
v0.0.0-...-af5a29e Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package testutil holds the smallest, most widely used test helper: Must. Everything else (fakes, gin contexts, golden files, a test database) lives in its own subpackage so a test imports only what it needs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Must

func Must[T any](v T, err error) func(t TB) T

Must checks the (value, error) pair a fixture call returns and gives back a function that yields the value, or fails the test the way t.Fatalf would. The pair must be Must's only arguments, because Go spreads a multi-value call into another call only when it is the sole argument, so t comes after:

user := testutil.Must(factory.User(ctx, db))(t)

Types

type TB

type TB interface {
	Helper()
	Fatalf(format string, args ...any)
}

TB is the subset of testing.TB that Must needs. *testing.T and *testing.B satisfy it. A test that wants to assert on Must's own failure path (as opposed to using Must to set up a fixture) can pass a fake that records the call instead of stopping the real test.

Directories

Path Synopsis
Package factory builds valid rows for pcom's tables so that tests (and cmd/seed) don't have to know the schema.
Package factory builds valid rows for pcom's tables so that tests (and cmd/seed) don't have to know the schema.
Package fakesender is a fake of github.com/can3p/pcom/pkg/repo.MailQueue for unit and package tests: it records every mail instead of delivering it.
Package fakesender is a fake of github.com/can3p/pcom/pkg/repo.MailQueue for unit and package tests: it records every mail instead of delivering it.
Package fakestorage is an in-memory implementation of github.com/can3p/pcom/pkg/media/server.MediaStorage, for tests that exercise upload/download code without a real object store.
Package fakestorage is an in-memory implementation of github.com/can3p/pcom/pkg/media/server.MediaStorage, for tests that exercise upload/download code without a real object store.
Package ginctx builds a *gin.Context for a handler test, wired up the way cmd/web/main.go wires a real request: a cookie-backed session under the name "sess".
Package ginctx builds a *gin.Context for a handler test, wired up the way cmd/web/main.go wires a real request: a cookie-backed session under the name "sess".
Package golden compares test output against a checked-in file, the convention docs/testing.md uses for mail content: run with UPDATE_GOLDEN=1 to write the file, and without it to check the current output still matches.
Package golden compares test output against a checked-in file, the convention docs/testing.md uses for mail content: run with UPDATE_GOLDEN=1 to write the file, and without it to check the current output still matches.
Package seed fills a development database with a small, named world that exercises every feature of pcom.
Package seed fills a development database with a small, named world that exercises every feature of pcom.
Package testdb gives a test its own empty Postgres database with pcom's migrations applied.
Package testdb gives a test its own empty Postgres database with pcom's migrations applied.
Package testlog records what code under test logs, so a test can assert on the entries.
Package testlog records what code under test logs, so a test can assert on the entries.
Package tommy runs one tommy container (github.com/can3p/tommy) per test binary: the Mailjet API mail is sent to, and the S3 bucket user media is stored in.
Package tommy runs one tommy container (github.com/can3p/tommy) per test binary: the Mailjet API mail is sent to, and the S3 bucket user media is stored in.
Package wiremock runs one WireMock container per test binary.
Package wiremock runs one WireMock container per test binary.

Jump to

Keyboard shortcuts

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