apitest

package
v1.32.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 11 Imported by: 0

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

func New(t testing.TB, reg *api.Registry) *Contract

New compiles one validator per operation's application/json 200 response (hidden operations included) and one for the error envelope.

func (*Contract) AssertResponse

func (c *Contract) AssertResponse(t testing.TB, operationID string, status int, body []byte)

AssertResponse validates a response body against the operation's 200 schema (status 200) or the error envelope (any other status), and reports every failing field with t.Errorf, 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL