testkit

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Context

func Context(account, user uuid.UUID, roles ...string) context.Context

Context returns a context carrying a tenant and an actor, for testing a service or a repository directly.

func OperatorContext

func OperatorContext(user uuid.UUID) context.Context

OperatorContext returns a platform-operator context.

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

func Mount(t *testing.T, prefix string, apps ...module.App) *Harness

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 New

func New(t *testing.T, app *fiber.App) *Harness

New builds a harness around a Fiber app.

func (*Harness) Delete

func (h *Harness) Delete(path string) Response

Delete sends a DELETE.

func (*Harness) Do

func (h *Harness) Do(method, path string, body any) Response

Do sends a request and decodes the envelope.

func (*Harness) Get

func (h *Harness) Get(path string) Response

Get sends a GET.

func (*Harness) Patch

func (h *Harness) Patch(path string, body any) Response

Patch sends a PATCH with a JSON body.

func (*Harness) Post

func (h *Harness) Post(path string, body any) Response

Post sends a POST with a JSON body.

func (*Harness) Put

func (h *Harness) Put(path string, body any) Response

Put sends a PUT with a JSON body.

func (*Harness) WithHeader

func (h *Harness) WithHeader(key, value string) *Harness

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) Errors

func (r Response) Errors() []errs.Detail

Errors returns the field-scoped details.

func (Response) ExpectCode

func (r Response) ExpectCode(t *testing.T, want string) Response

ExpectCode fails the test unless meta.code matches.

func (Response) ExpectFieldError

func (r Response) ExpectFieldError(t *testing.T, field string) Response

ExpectFieldError fails the test unless a validation detail names field.

func (Response) ExpectStatus

func (r Response) ExpectStatus(t *testing.T, want int) Response

ExpectStatus fails the test unless the status matches, printing the body — which is what you actually want to see when it does not.

func (Response) JSON

func (r Response) JSON(t *testing.T, dst any)

JSON decodes the payload into dst.

Jump to

Keyboard shortcuts

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