Documentation
¶
Overview ¶
Package humatest provides testing utilities for Huma services. It is based on the `chi` router and the standard library `http.Request` & `http.ResponseWriter` types.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAdapter ¶
func NewAdapter(r chi.Router) huma.Adapter
NewAdapter creates a new adapter for the given chi router.
func NewContext ¶
func NewContext(op *huma.Operation, r *http.Request, w http.ResponseWriter) huma.Context
NewContext creates a new test context from a request/response pair.
Types ¶
type TB ¶
TB is a subset of the `testing.TB` interface used by the test API and implemented by the `*testing.T` and `*testing.B` structs.
type TestAPI ¶
type TestAPI interface { huma.API // Do a request against the API. Args, if provided, should be string headers // like `Content-Type: application/json` or an `io.Reader` for the request // body. Anything else will panic. Do(method, path string, args ...any) *httptest.ResponseRecorder // Get performs a GET request against the API. Args, if provided, should be // string headers like `Content-Type: application/json` or an `io.Reader` // for the request body. Anything else will panic. Get(path string, args ...any) *httptest.ResponseRecorder // Post performs a POST request against the API. Args, if provided, should be // string headers like `Content-Type: application/json` or an `io.Reader` // for the request body. Anything else will panic. Post(path string, args ...any) *httptest.ResponseRecorder // Put performs a PUT request against the API. Args, if provided, should be // string headers like `Content-Type: application/json` or an `io.Reader` // for the request body. Anything else will panic. Put(path string, args ...any) *httptest.ResponseRecorder // Patch performs a PATCH request against the API. Args, if provided, should // be string headers like `Content-Type: application/json` or an `io.Reader` // for the request body. Anything else will panic. Patch(path string, args ...any) *httptest.ResponseRecorder // Delete performs a DELETE request against the API. Args, if provided, should // be string headers like `Content-Type: application/json` or an `io.Reader` // for the request body. Anything else will panic. Delete(path string, args ...any) *httptest.ResponseRecorder }
TestAPI is a `huma.API` with additional methods specifically for testing.
func New ¶
New creates a new router and test API, making it easy to register operations and perform requests against them. Optionally takes a configuration object to customize how the API is created. If no configuration is provided then a simple default configuration supporting `application/json` is used.
func NewTestAPI ¶
NewTestAPI creates a new test API from a chi router and API config.