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 ¶
- func AccessMatrix(t testing.TB, table *httpwire.Table, guard httpwire.Guard, creds []Credential, ...)
- func Contract(t testing.TB, api *httpwire.API, cases []Case, opts ...Option)
- func Sentinels(t testing.TB, owner *httpwire.Owner)
- type Case
- type Credential
- type CredentialKind
- type Option
- type SameShape
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AccessMatrix ¶
func AccessMatrix(t testing.TB, table *httpwire.Table, guard httpwire.Guard, creds []Credential, opts ...httpwire.Option)
AccessMatrix builds an API of table with guard and opts, every row of table.Endpoints bound to a stub, and serves each row once per credential over HTTPS. It fails t, naming the row and the credential, wherever the answer is not the code the row's Access gives (docs/testing.md lists them) or the row does not run as the credential's principal where Access admits it; a row the guard answers without running it fails as not served. A table New refuses fails t at once.
func Contract ¶
Contract serves each case through api and fails t, naming the row, on any answer outside the row's shapes in the document api was built with (a status, body, media type, envelope, Wire-Version or this request's X-Request-Id; a refusal's request_id may name an earlier request, as a replay's does, and a HEAD answer's body is not read), and fails every write row, mount rows included, whose union holds outcome_unknown and that is not Keyed. docs/testing.md lists each check.
func Sentinels ¶
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. A case naming no row, a Stream row, or a request the API routes to another row fails.
type Credential ¶
type Credential struct {
// Apply answers a copy of the request carrying the credential.
Apply func(*http.Request) *http.Request
Name string
// Scopes are every scope a Key passes, or a session's role grants,
// those it implies included.
Scopes []string
Kind CredentialKind
}
Credential is one principal AccessMatrix serves every row as.
type CredentialKind ¶
type CredentialKind uint8
CredentialKind is what a Credential presents.
const ( None CredentialKind = iota + 1 // no credential Session // a session past its recent-authentication window SessionRecent // a session authenticated recently Key // a valid API key KeyInvalid // a revoked or expired key )
The credential kinds.
type Option ¶
type Option func(*options)
Option configures Contract.
func WithSameShape ¶
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.