test

package
v0.0.0-...-2da20e2 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 18 Imported by: 0

README

How one can be sure that lovely 🌸🌸🌸 is not producing 💩💩💩

We utilize different testing layers:

  • API (Integration Tests): These validate the request-response cycle and any resulting side effects. You send a payload, check the response, and verify the system behaves as expected. (See existing tests for examples).
  • Services: These cover internal business logic that isn't always exposed via the API. For example, if you need to offboard users or clean up accounts based on specific criteria, test the logic here.
  • Workers: Our background processes that run on a schedule. Here you can seed your data and manually trigger a job to make sure it actually does its thing.

Setup

Each of these layers requires a real database connection. Please refer to ../SETUP.md for help with the test database and its specific configuration.

Documentation

Overview

Package test ...

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoFactoryMethod is returned when no suitable factory method
	// can be found for the requested type.
	ErrNoFactoryMethod = errors.New("no factory method found")

	// ErrAmbiguousFactoryMethod is returned when multiple factory methods
	// match the requested type and the selection is ambiguous.
	ErrAmbiguousFactoryMethod = errors.New("ambiguous factory method")
)
View Source
var NotNull notNull

NotNull is the exported constant marker value to assert that a database column must not be NULL. Use it as a value in a Data map: Data{"column_name": test.NotNull}.

Functions

func AssertDeleted

func AssertDeleted(t *testing.T, db *app.DB, table string, id ds.ID)

AssertDeleted asserts that row with "deleted_at" is not null.

func AssertInDB

func AssertInDB(t *testing.T, db *app.DB, table string, data Data)

AssertInDB asserts that at least one row exists in the given table that matches the criteria in 'data'.

func AssertNotInDB

func AssertNotInDB(t *testing.T, db *app.DB, table string, data Data)

AssertNotInDB asserts that no rows exist in the given table that match the criteria in 'data'.

func CheckErr

func CheckErr(t *testing.T, err error)

CheckErr is a test helper function that fails the test immediately if the provided error is not nil.

func Create

func Create[T any](t *testing.T, f *factory.Factory, overrideOpt ...T) *T

Create invokes the corresponding Create{Model} method on factory.Factory, where Model is inferred from T.

Optional overrideOpt values are forwarded as variadic arguments to the underlying factory method. The test fails immediately on any error.

NOTE: Go does not currently allow methods to declare their own type parameters. When this becomes possible, move this helper onto *factory.Factory and remove the wrapper functions. TODO: a promising "Proposal: Generic Methods for Go" have landed: https://github.com/golang/go/issues/77273

func LoadEmailVars

func LoadEmailVars(t *testing.T, to string) map[string]any

LoadEmailVars retrieves the template variables from the most recent email sent to the given recipient via the TestSender email driver.

Types

type App

type App struct {
	Conf    *app.ConfigT
	Tracer  otelTrace.Tracer
	DB      *app.DB
	Service *service.Service
	Factory *factory.Factory
}

App holds common dependencies for tests among different test namespaces.

func NewApp

func NewApp() *App

NewApp ...

func (*App) Shutdown

func (a *App) Shutdown()

Shutdown ... Initiator of NewApp must care to call Shutdown().

type Data

type Data map[string]any

Data is a type alias representing a map of database columns and their expected values, used for assertions against the database.

Directories

Path Synopsis
random
Package random provides utility functions for generating various types of random data.
Package random provides utility functions for generating various types of random data.
Package seed provides helpers for seeding test and development data.
Package seed provides helpers for seeding test and development data.

Jump to

Keyboard shortcuts

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