Documentation
¶
Overview ¶
Package testhelpers provides shared utilities for tests across all packages.
Index ¶
Constants ¶
const ( // SuffixOK simulates the happy path — no error. SuffixOK = "00" // SuffixForbidden simulates data.ErrForbidden (HTTP 403). SuffixForbidden = "03" // SuffixNotFound simulates data.ErrNotFound (HTTP 404). SuffixNotFound = "04" // SuffixInternal simulates data.ErrInternal (HTTP 500). SuffixInternal = "05" // SuffixConflict simulates data.ErrConflict (HTTP 409). SuffixConflict = "09" )
Suffix* constants define the project-wide convention for simulating repo-layer outcomes from a test UUID: the trailing two hex characters of the UUID select which sentinel error (if any) a stub or mock should return.
Variables ¶
This section is empty.
Functions ¶
func ErrorForUUID ¶
ErrorForUUID returns the sentinel error a stub should simulate for id, based on its trailing two hex characters, or nil for the happy path.
func NewEcho ¶
NewEcho returns an Echo instance with the DTO validator registered, suitable for use in HTTP handler tests.
func NewUUIDWithSuffix ¶
NewUUIDWithSuffix returns a random UUID whose trailing two hex characters are suffix, for building deterministic test fixtures, e.g.:
testhelpers.NewUUIDWithSuffix(testhelpers.SuffixNotFound)
func SetupTestDB ¶
SetupTestDB opens an in-memory SQLite database and applies all migrations. The database is closed automatically when the test ends.
func WithTxRollback ¶
WithTxRollback runs fn inside a transaction that is always rolled back, giving each sub-test a clean, isolated view of the database.
The *db.Queries passed to fn are bound to the transaction — pass them to repo constructors (e.g. repo.NewUserRepo) rather than calling sqlc methods directly, to keep tests free of raw SQL.