Documentation
¶
Overview ¶
Package apitest checks recorded responses against the contract of an api.Registry: the strict OpenAPI 3.1 document, where every response object component has additionalProperties:false so undocumented fields fail. Non-JSON 200 responses (api.Blob) are checked against the operation's declared media types. The body of a HEAD operation's response is not checked: it has none.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Contract ¶
type Contract struct {
// contains filtered or unexported fields
}
Contract validates responses of a registry's operations.
func New ¶
New compiles one validator per operation's application/json 200 response (hidden operations included) and one for the error envelope.
func (*Contract) AssertResponse ¶
AssertResponse validates a response body against the operation's 200 schema (status 200) or the error envelope (any other status), and reports the failing fields with t.Errorf (the first validate.MaxFields of them and a count of the rest), that an object repeats a key, or that the body is empty. The body of a HEAD operation's response is not checked: rest.ErrorHandler answers a HEAD request with the status alone.
func (*Contract) Do ¶
func (c *Contract) Do(t testing.TB, e *echo.Echo, operationID string, req *http.Request) *httptest.ResponseRecorder
Do serves req on e, asserts the response matches the contract and returns the recorder. A 200 response that is not application/json must carry one of the operation's declared media types.