contracttest

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package contracttest checks HTTP exchanges against the public contract, api/openapi.yaml. Handler tests use it to prove that what the API really answers is what the contract says.

Index

Constants

This section is empty.

Variables

View Source
var ErrUndocumented = errors.New("operation not in the contract")

ErrUndocumented means the contract has no operation for the request's method and path.

Functions

This section is empty.

Types

type Contract

type Contract struct {
	// contains filtered or unexported fields
}

Contract is the public contract, ready to check exchanges against.

func Load

func Load() (*Contract, error)

Load reads and validates the contract of package api. In its copy, every object schema of a response rejects undocumented properties: clients must ignore the fields they do not know, but the API must not send any. Request schemas stay open.

func (*Contract) Check

func (c *Contract) Check(ctx context.Context, req *http.Request, res *http.Response) error

Check returns an error unless req and res follow the contract: the operation is documented, the request's parameters and body are valid, and the response's status, headers, content type and body are the documented ones. It reads and closes both bodies.

Jump to

Keyboard shortcuts

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