contracttest

package
v0.41.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: 10 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 ErrNoCredentials = errors.New("no credentials of the required scheme")

ErrNoCredentials means a request lacks the Authorization field its operation's security requirement asks for.

View Source
var ErrRequestValid = errors.New("request follows the contract")

ErrRequestValid means CheckRefused was given a request the contract accepts: Check is the one to hold it.

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.

func (*Contract) CheckRefused added in v0.35.0

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

CheckRefused returns an error unless req is a documented operation the contract refuses, such as one without a required parameter, and res is a documented answer to it. It is how the problems answering invalid requests are held to the contract. It reads and closes both bodies.

Jump to

Keyboard shortcuts

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