Documentation
¶
Overview ¶
Package requesttest provides reusable OpenAPI request-contract helpers for handler tests.
Index ¶
- func AssertCases(t *testing.T, validator *Validator, cases []Case)
- func AssertRecorderResponse(t testing.TB, validator *Validator, req *http.Request, ...)
- func NewFormRequest(method string, target string, body string) *http.Request
- func NewJSONRequest(method string, target string, body string) *http.Request
- func NewRequest(method string, target string, contentType string, body string) *http.Request
- func RequireStringPointer(t testing.TB, name string, got *string, want string)
- func RequireStringSlicePointer(t testing.TB, name string, got *[]string, want []string)
- func RoundTripJSON(t testing.TB, source any, target any)
- func WithHeaders(req *http.Request, values map[string]string) *http.Request
- type Case
- type ClientSmokeDoer
- type ClientSmokeRoute
- type ResponseValidation
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertCases ¶
AssertCases validates a table of valid and invalid request samples.
func AssertRecorderResponse ¶
func AssertRecorderResponse( t testing.TB, validator *Validator, req *http.Request, recorder *httptest.ResponseRecorder, validation ResponseValidation, )
AssertRecorderResponse validates recorder against the OpenAPI operation that matches req.
func NewFormRequest ¶
NewFormRequest builds an httptest request with a form-urlencoded body.
func NewJSONRequest ¶
NewJSONRequest builds an httptest request with an application/json body.
func NewRequest ¶
NewRequest builds an httptest request with an optional Content-Type header.
func RequireStringPointer ¶
RequireStringPointer verifies an optional generated string field.
func RequireStringSlicePointer ¶
RequireStringSlicePointer verifies an optional generated string slice field.
func RoundTripJSON ¶
RoundTripJSON marshals source and unmarshals it into target for adapter tests that verify two DTOs share the same JSON boundary.
Types ¶
type Case ¶
type Case struct {
Request *http.Request
Name string
WantErrorContains string
ForbiddenErrorSubstrings []string
WantValid bool
}
Case describes one request-contract validation sample.
type ClientSmokeDoer ¶
type ClientSmokeDoer struct {
// contains filtered or unexported fields
}
ClientSmokeDoer handles generated-client requests without opening a socket.
func NewClientSmokeDoer ¶
func NewClientSmokeDoer(t testing.TB, route ClientSmokeRoute) *ClientSmokeDoer
NewClientSmokeDoer creates a focused in-memory doer for generated-client tests that should verify request construction and response parsing only.
type ClientSmokeRoute ¶
type ClientSmokeRoute struct {
Request any
Response any
ResponseBody []byte
Headers map[string]string
ContentType string
Method string
Path string
Status int
}
ClientSmokeRoute describes the single generated-client request accepted by a smoke server.
type ResponseValidation ¶
type ResponseValidation = requestvalidation.ResponseValidation
ResponseValidation configures response-contract checks around a real httptest response.
type Validator ¶
type Validator struct {
*requestvalidation.Validator
}
Validator wraps the runtime-safe OpenAPI request validator with testing constructors.
func NewIDPValidator ¶
NewIDPValidator loads the IDP OpenAPI document.
func NewManagementValidator ¶
NewManagementValidator loads the management OpenAPI document.
func (*Validator) ValidateRecorderResponse ¶
func (validator *Validator) ValidateRecorderResponse( req *http.Request, recorder *httptest.ResponseRecorder, validation ResponseValidation, ) error
ValidateRecorderResponse validates a httptest recorder response against the matching OpenAPI operation.