Documentation
¶
Overview ¶
Package gpptest provides typed helpers for exercising gpp applications through httptest without opening network sockets.
Index ¶
- func Decode[T any](response *ResponseWrapper) T
- func ParseProblemDetails(body []byte) (gpp.ProblemDetails, error)
- type ResponseWrapper
- func (r *ResponseWrapper) AssertContains(substring string) *ResponseWrapper
- func (r *ResponseWrapper) AssertContentType(expected string) *ResponseWrapper
- func (r *ResponseWrapper) AssertHeader(name, expected string) *ResponseWrapper
- func (r *ResponseWrapper) AssertJSON(key string, expected any) *ResponseWrapper
- func (r *ResponseWrapper) AssertJSONPath(path string, expected any) *ResponseWrapper
- func (r *ResponseWrapper) AssertProblem(status int, problemType string) *ResponseWrapper
- func (r *ResponseWrapper) AssertRequestID() *ResponseWrapper
- func (r *ResponseWrapper) AssertStatus(expected int) *ResponseWrapper
- func (r *ResponseWrapper) AssertViolation(field, rule string) *ResponseWrapper
- func (r *ResponseWrapper) DecodeInto(target any) *ResponseWrapper
- func (r *ResponseWrapper) Problem() gpp.ProblemDetails
- type Tester
- func (st *Tester) DELETE(target string) *ResponseWrapper
- func (st *Tester) GET(target string) *ResponseWrapper
- func (st *Tester) POST(target string, body any) *ResponseWrapper
- func (st *Tester) PUT(target string, body any) *ResponseWrapper
- func (st *Tester) Request(method, target string, body any, headers map[string]string) *ResponseWrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
func Decode[T any](response *ResponseWrapper) T
Decode parses a response JSON body into T and fails the active test on error.
func ParseProblemDetails ¶
ParseProblemDetails strictly decodes one valid RFC 7807 document.
Types ¶
type ResponseWrapper ¶
type ResponseWrapper struct {
Recorder *httptest.ResponseRecorder
// contains filtered or unexported fields
}
ResponseWrapper wraps httptest.ResponseRecorder with ergonomic assertion helpers.
func (*ResponseWrapper) AssertContains ¶
func (r *ResponseWrapper) AssertContains(substring string) *ResponseWrapper
AssertContains asserts that the response body contains a expected substring.
func (*ResponseWrapper) AssertContentType ¶
func (r *ResponseWrapper) AssertContentType(expected string) *ResponseWrapper
AssertContentType verifies the parsed response media type.
func (*ResponseWrapper) AssertHeader ¶
func (r *ResponseWrapper) AssertHeader(name, expected string) *ResponseWrapper
AssertHeader verifies an exact response header value.
func (*ResponseWrapper) AssertJSON ¶
func (r *ResponseWrapper) AssertJSON(key string, expected any) *ResponseWrapper
AssertJSON asserts that a JSON field in the response body equals the expected value.
func (*ResponseWrapper) AssertJSONPath ¶
func (r *ResponseWrapper) AssertJSONPath(path string, expected any) *ResponseWrapper
AssertJSONPath verifies a dot-separated object or array path in a JSON response.
func (*ResponseWrapper) AssertProblem ¶
func (r *ResponseWrapper) AssertProblem(status int, problemType string) *ResponseWrapper
AssertProblem verifies the HTTP and problem status plus an optional problem type.
func (*ResponseWrapper) AssertRequestID ¶
func (r *ResponseWrapper) AssertRequestID() *ResponseWrapper
AssertRequestID verifies response correlation and Problem Details trace IDs.
func (*ResponseWrapper) AssertStatus ¶
func (r *ResponseWrapper) AssertStatus(expected int) *ResponseWrapper
AssertStatus asserts that the response HTTP status code matches expected.
func (*ResponseWrapper) AssertViolation ¶
func (r *ResponseWrapper) AssertViolation(field, rule string) *ResponseWrapper
AssertViolation verifies that a Problem Details response contains a field violation.
func (*ResponseWrapper) DecodeInto ¶
func (r *ResponseWrapper) DecodeInto(target any) *ResponseWrapper
DecodeInto strictly decodes a response body. Empty 204 responses leave the target unchanged; empty bodies for other statuses fail the test.
func (*ResponseWrapper) Problem ¶
func (r *ResponseWrapper) Problem() gpp.ProblemDetails
Problem decodes and validates an RFC 7807 response body.
type Tester ¶
type Tester struct {
// contains filtered or unexported fields
}
Tester provides simple 3-line E2E API integration testing for goplusplus applications.
func (*Tester) DELETE ¶
func (st *Tester) DELETE(target string) *ResponseWrapper
DELETE performs a simulated DELETE request.
func (*Tester) GET ¶
func (st *Tester) GET(target string) *ResponseWrapper
GET performs a simulated GET request.
func (*Tester) POST ¶
func (st *Tester) POST(target string, body any) *ResponseWrapper
POST performs a simulated POST request with a JSON body.