apitest

package
v0.0.0-...-0b22273 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package apitest holds a server to the API's description, api.OpenAPI, in tests. Handler wraps a server's handler, and checks what passes through it:

  • every answer, in strict mode, so a member, a status or a header the description does not name fails, as does one it requires and the answer lacks (a header it does not name is looked for only once every header it names is right: the validator checks that last);
  • every request: one the description refuses must not be answered 2xx;
  • a route the description lacks gets the router's plain 404 or 405;
  • every error's code counts (protocol.Problem.CodeAt): one the description knows, under its own status, beside its own type;
  • an answer in gzip is one to a request that takes gzip, and is checked as the JSON beneath; the description says which answers may be.

The server and the Go client share protocol's structs, so a member that drifts from PROTOCOL.md passes every test the two run together. This is what fails then.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(t testing.TB, h http.Handler) http.Handler

Handler returns h, with each request and answer checked against the description and every disagreement reported to t.

func Routes

func Routes() ([]string, error)

Routes returns each operation the description has, as "METHOD /path", sorted: what a server's own list of routes is held to, so a route added on one side and not the other fails.

func Validator

func Validator() (validator.Validator, error)

Validator returns the strict validator of api.OpenAPI, built once.

Types

This section is empty.

Jump to

Keyboard shortcuts

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