Documentation
¶
Overview ¶
Package apitest provides HTTP response assertions for application tests.
The package is stable core API for tests. It builds on httptest.ResponseRecorder semantics and complements contracttest: contracttest checks route registries and OpenAPI metadata, while apitest checks concrete HTTP responses emitted by handlers.
Use AssertProblem, AssertProblemCode, AssertValidationFields, AssertJSON, AssertHeader, AssertRateLimitHeaders, AssertETag, AssertDeprecationHeaders, AssertPagination, AssertOperationAccepted, AssertWebhookSignature, and AssertOpenAPIGolden to keep API tests focused on externally visible behavior.
These helpers call testing.TB.Fatal when assertions fail. They are not runtime middleware and should not be imported by production handlers. For examples, see docs/cookbook.md.
Index ¶
- func AssertDeprecationHeaders(t testing.TB, recorder *httptest.ResponseRecorder)
- func AssertETag(t testing.TB, recorder *httptest.ResponseRecorder, want string)
- func AssertHeader(t testing.TB, recorder *httptest.ResponseRecorder, name, want string)
- func AssertJSON(t testing.TB, recorder *httptest.ResponseRecorder, want any)
- func AssertOpenAPIGolden(t testing.TB, got, golden []byte)
- func AssertOperationAccepted(t testing.TB, recorder *httptest.ResponseRecorder, location string)
- func AssertPagination(t testing.TB, recorder *httptest.ResponseRecorder, count, limit int)
- func AssertProblem(t testing.TB, recorder *httptest.ResponseRecorder, status int) map[string]any
- func AssertProblemCode(t testing.TB, recorder *httptest.ResponseRecorder, code httpx.ProblemCode)
- func AssertRateLimitHeaders(t testing.TB, recorder *httptest.ResponseRecorder)
- func AssertValidationFields(t testing.TB, recorder *httptest.ResponseRecorder, fields ...string)
- func AssertWebhookSignature(t testing.TB, header http.Header, name string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertDeprecationHeaders ¶
func AssertDeprecationHeaders(t testing.TB, recorder *httptest.ResponseRecorder)
AssertDeprecationHeaders asserts runtime deprecation headers.
func AssertETag ¶
func AssertETag(t testing.TB, recorder *httptest.ResponseRecorder, want string)
AssertETag asserts the ETag response header.
func AssertHeader ¶
func AssertHeader(t testing.TB, recorder *httptest.ResponseRecorder, name, want string)
AssertHeader asserts a response header value.
func AssertJSON ¶
func AssertJSON(t testing.TB, recorder *httptest.ResponseRecorder, want any)
AssertJSON asserts a JSON response body.
func AssertOpenAPIGolden ¶
AssertOpenAPIGolden asserts normalized OpenAPI JSON against a golden document.
func AssertOperationAccepted ¶
func AssertOperationAccepted(t testing.TB, recorder *httptest.ResponseRecorder, location string)
AssertOperationAccepted asserts a 202 operation response.
func AssertPagination ¶
func AssertPagination(t testing.TB, recorder *httptest.ResponseRecorder, count, limit int)
AssertPagination asserts common list metadata values.
func AssertProblem ¶
AssertProblem asserts a Problem Details response and returns the decoded body.
func AssertProblemCode ¶
func AssertProblemCode(t testing.TB, recorder *httptest.ResponseRecorder, code httpx.ProblemCode)
AssertProblemCode asserts a typed problem code extension.
func AssertRateLimitHeaders ¶
func AssertRateLimitHeaders(t testing.TB, recorder *httptest.ResponseRecorder)
AssertRateLimitHeaders asserts standard quota headers exist.
func AssertValidationFields ¶
func AssertValidationFields(t testing.TB, recorder *httptest.ResponseRecorder, fields ...string)
AssertValidationFields asserts validation field names in a Problem Details response.
Types ¶
This section is empty.