hxtest

package
v0.0.0-...-b711e6f Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package hxtest provides a fluent API for testing hx.HandlerFunc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Check

type Check func(t testing.TB, r *Result)

Check is a test check applied to a Result.

func Body

func Body(want any, opts ...cmp.Option) Check
func Header(key, want string) Check

func HeaderHas

func HeaderHas(key, substr string) Check

func IsProblem

func IsProblem(problem error) Check

IsProblem asserts RFC 9457 style response (& Content-Type).

func NoBody

func NoBody() Check

func ProblemDetail

func ProblemDetail(substr string) Check

func ProblemTitle

func ProblemTitle(substr string) Check

func Status

func Status(code int) Check

type Result

type Result struct {
	ContentType string
	Status      int
	Header      http.Header

	Body     any
	Hijacked bool
	Err      error

	Problem *out.ProblemDetails
}

Result is a materialized HTTP response produced by running a handler.

type Tester

type Tester struct {
	// contains filtered or unexported fields
}

Tester is the harness builder. Create via Test(t, handler).

func Test

func Test(t testing.TB, h hx.HandlerFunc) *Tester

Test initializes a test harness for a single handler.

func (*Tester) DebugBody

func (tt *Tester) DebugBody(b bool) *Tester

DebugBody enables debug logging of the response body.

func (*Tester) Do

func (tt *Tester) Do(req *http.Request) *Result

Do run the handler against req, honoring HijackResponseWriter semantics, materializes the result, then runs queued expectations (fail-fast).

func (*Tester) Expect

func (tt *Tester) Expect(e Check) *Tester

Expect queues an assertion to run after the handler is executed.

func (*Tester) Expects

func (tt *Tester) Expects(ee ...Check) *Tester

Expects queues multiple assertions to run after the handler is executed.

func (*Tester) WithContext

func (tt *Tester) WithContext(mut func(ctx context.Context) context.Context) *Tester

WithContext lets you mutate the request context before invocation.

Jump to

Keyboard shortcuts

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