Documentation
¶
Overview ¶
Package sequence scripts a mock's answers. A scenario names, per route, the sequence of responses the route gives: the Nth request to the route gets the Nth response and the last one repeats, so a poll loop sees state advance (pending, pending, completed) and a check that never reports stays where it is. The mocks of GitHub, CircleCI and the registry share this dispatcher and add their own headers and defaults on top.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Response ¶
type Response struct {
// Status is the HTTP status; 0 reads as 200.
Status int `yaml:"status"`
// Headers are set on the response. A mock adds its own defaults for the
// headers a fixture leaves out and never overrides one the fixture sets.
Headers map[string]string `yaml:"headers"`
// Body is sent as JSON when it is a mapping or a list, verbatim when it is
// a string, and as an empty body when it is absent.
Body any `yaml:"body"`
}
Response is one scripted answer of a route.
func (Response) Header ¶
Header is the fixture's headers as an http.Header, so lookups are case-insensitive.
func (Response) StatusCode ¶
StatusCode is the status the response is sent with.
type Routes ¶
Routes maps a route key, "METHOD /path" or "METHOD /path?key=value", to the route's responses. A key with a query matches a request whose query carries every listed parameter with the listed value, whatever else the request sends; a key without a query matches any query. Of several matching routes the one with the most query parameters wins.
type Script ¶
type Script struct {
// contains filtered or unexported fields
}
Script dispatches requests to routes and records every request it sees.
func New ¶
New compiles the routes. A key that is not "METHOD /path[?query]" or a route without responses is an error, so a scenario's typo fails its run.
func (*Script) Next ¶
Next records the request and returns the matching route's next response. ok is false when no route matches; the request is recorded all the same.