contracttest

package
v0.60.0 Latest Latest
Warning

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

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

Documentation

Overview

Package contracttest checks answers against the public contract, api/openapi.yaml. The HTTP handler and MCP server tests use it to prove that what they really answer 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.

View Source
var ErrUnknownSchema = errors.New("schema not in the contract")

ErrUnknownSchema means the contract has no component schema of the name CheckSchema is given.

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

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.

func (*Contract) CheckSchema

func (c *Contract) CheckSchema(name string, v any) error

CheckSchema returns an error unless v, once written in JSON, follows the contract's component schema name, closed as a response's is. Answers that are not HTTP responses, such as the MCP server's, are held to the contract with it.

Jump to

Keyboard shortcuts

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