Documentation
¶
Overview ¶
Package testkit makes a module testable without a server, a port or a sleep.
An application assembled in memory, exercised through Fiber's own test transport, with the response envelope decoded for you.
The point is that these are not unit tests with the HTTP layer mocked away. They go through the real middleware, the real guards and the real exception filter, which is where most of the behaviour this framework provides actually lives — and where a mock would quietly diverge.
Index ¶
- func Context(account, user uuid.UUID, roles ...string) context.Context
- func OperatorContext(user uuid.UUID) context.Context
- type Harness
- func (h *Harness) Delete(path string) Response
- func (h *Harness) Do(method, path string, body any) Response
- func (h *Harness) Get(path string) Response
- func (h *Harness) Patch(path string, body any) Response
- func (h *Harness) Post(path string, body any) Response
- func (h *Harness) Put(path string, body any) Response
- func (h *Harness) WithHeader(key, value string) *Harness
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Harness ¶
type Harness struct {
T *testing.T
App *fiber.App
// Headers are sent on every request — a bearer token, a tenant header.
Headers map[string]string
}
Harness is an application under test.
func Mount ¶
Mount builds a harness that serves the given apps under prefix, with no middleware beyond what the modules declare.
Use it for a module test. For a test of the whole service, build the real inceptools.Application and hand its Fiber app to New — otherwise the test passes through a pipeline the production one does not have.
func (*Harness) WithHeader ¶
WithHeader adds a header to every subsequent request.
type Response ¶
type Response struct {
Status int
Body []byte
Meta response.Meta
// Data is the raw payload, still encoded, so a test can decode it into
// whatever type that endpoint returns.
Data json.RawMessage
}
Response is a decoded reply.
func (Response) ExpectCode ¶
ExpectCode fails the test unless meta.code matches.
func (Response) ExpectFieldError ¶
ExpectFieldError fails the test unless a validation detail names field.
func (Response) ExpectStatus ¶
ExpectStatus fails the test unless the status matches, printing the body — which is what you actually want to see when it does not.