Documentation
¶
Overview ¶
Package testutil provides shared test infrastructure for integration tests. Use testutil.Main in TestMain functions to compose infrastructure options.
Index ¶
- Variables
- func MustMarshalJSON(v any) string
- func RequireStatus(t *testing.T, err error, expectedCode int)
- func ScrubField(data map[string]any, field string)
- func ScrubFields(data map[string]any, fields ...string)
- func UniqueID() string
- type Fixtures
- type M
- type Option
- type State
- func (s *State) Delete(path string) (map[string]any, error)
- func (s *State) DeleteStatus(path string) error
- func (s *State) Get(path string) (map[string]any, error)
- func (s *State) GetStatus(path string) error
- func (s *State) Post(path string, body any) (map[string]any, error)
- func (s *State) PostStatus(path string, body any) error
- func (s *State) Put(path string, body any) (map[string]any, error)
- type StatusError
- type Teardown
Constants ¶
This section is empty.
Variables ¶
var AdminCreds struct { Email string Password string }
AdminCreds holds the email and password of the single admin user created by WithAdminUser. Tests that need an authenticated session should use these credentials via NewAuthState, which logs in using them.
Functions ¶
func MustMarshalJSON ¶
MustMarshalJSON marshals v to a JSON string, panicking on error. Useful for building approval test inputs inline.
func RequireStatus ¶
RequireStatus asserts that err is a *StatusError with the expected code, or that err is nil when expectedCode is 2xx. Fails the test immediately.
func ScrubField ¶
ScrubField replaces the value of a key in a decoded JSON map with "[SCRUBBED]". This is used before snapshot assertions to mask non-deterministic fields like IDs and timestamps.
func ScrubFields ¶
ScrubFields scrubs multiple fields from a decoded JSON map.
Types ¶
type M ¶
type M struct {
// contains filtered or unexported fields
}
M wraps *testing.M and manages ordered infrastructure setup and teardown.
type Option ¶
type Option func() Teardown
Option sets up a piece of test infrastructure and returns its teardown.
func WithAdminUser ¶
func WithAdminUser() Option
WithAdminUser returns an Option that creates the single admin user directly in the database (bypassing the signup endpoint's one-user guard). It must be composed after WithPostgres() so the DB pool is ready.
func WithApprovals ¶
func WithApprovals() Option
WithApprovals returns an Option that configures the go-approval-tests reporter and snapshot folder. When the -accept-changes flag is set, all diffs are auto-approved.
func WithEncryptionKey ¶
func WithEncryptionKey() Option
WithEncryptionKey returns an Option that generates a random encryption key and stores it in the settings table. Use this in TestMain for tests that interact with git tokens or other encrypted data but do not call WithAdminUser.
func WithPostgres ¶
func WithPostgres() Option
WithPostgres returns an Option that starts a Postgres 17.7 container, runs migrations, and injects the pool into the db package. The container is terminated on teardown.
func WithQdrant ¶
func WithQdrant() Option
WithQdrant returns an Option that starts a Qdrant v1.17.0 container, ensures the collection exists, and injects the gRPC connection into the qdrant package. The container is terminated on teardown.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State holds the test Echo server and provides HTTP helper methods.
func NewAuthState ¶
NewAuthState creates a State with a session cookie pre-set by logging in as the admin user created by WithAdminUser(). Tests using this helper must include WithAdminUser() in their TestMain options.
func NewState ¶
NewState creates a State backed by a minimal Echo server with all routes registered.
func (*State) DeleteStatus ¶
DeleteStatus performs a DELETE request and returns only the error.
func (*State) GetStatus ¶
GetStatus performs a GET request and returns only the error (useful for asserting non-2xx status codes without caring about the body).
func (*State) PostStatus ¶
PostStatus performs a POST request and returns only the error.
type StatusError ¶
StatusError is returned when a response has a non-2xx status code.
func (*StatusError) Error ¶
func (e *StatusError) Error() string