httpwiretest

package
v1.0.0-dev.5 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package httpwiretest checks an app's httpwire API from its handler tests: every answer against the row's declared shapes in the document the API runs with, and each owner package's sentinels against its code table.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contract

func Contract(t testing.TB, api *httpwire.API, cases []Case, opts ...Option)

Contract serves each case through api and fails t, naming the row, on any answer outside the row's shapes in the OpenAPI document api was built with: an undeclared success status, a body that does not decode strictly into the status's Response type or breaks its schema, a Raw answer of another media type, an error that is not an envelope of a code in the row's union at the catalog's status, and no Wire-Version of this API or valid X-Request-Id. A HEAD answer's body is not read. A case naming no row, a Stream row, or a request the API routes to another row fails.

func Sentinels

func Sentinels(t testing.TB, owner *httpwire.Owner)

Sentinels fails t unless the exported Err* vars that the package in the working directory declares (its non-test files for this build, as go test sets the directory) are exactly the keys of owner.Sentinels, and owner passes every owner check New makes but the catalog's, so a sentinel with no code fails the owner package's own test.

Types

type Case

type Case struct {
	// Request is built by the test, carrying its own principal.
	Request *http.Request
	// Row is a row name of the API's table, mount rows included.
	Row string
}

Case is one request Contract serves.

type Option

type Option func(*options)

Option configures Contract.

func WithSameShape

func WithSameShape(s SameShape) Option

WithSameShape serves every case of a read row with Changes and no Personal as both principals, and fails the row when the guard gives them two shapes or their answers differ as JSON values (a List answer's cursors left out). Every such row then needs a case. It may be passed more than once; each pair runs over every such case.

type SameShape

type SameShape struct {
	// A and B each return a copy of the request carrying their principal.
	A, B func(*http.Request) *http.Request
}

SameShape names two principals of one shape (two users of one role, two keys of one scope) that own different records in the fixture store.

Jump to

Keyboard shortcuts

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