Documentation
¶
Overview ¶
Package httpfixture replays HTTP exchanges without simulating remote state.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Body ¶
type Body struct {
JSON any `yaml:"json"`
}
Body distinguishes an absent HTTP body from a JSON value, including JSON null.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler permits independent requests to interleave and consumes identical request signatures FIFO. A mutex keeps matching and consumption atomic.
func NewHandler ¶
func NewHandler() *Handler
NewHandler returns an empty handler; fixture sets are configured separately.
func (*Handler) ServeHTTP ¶
func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP prefers consumable step fixtures over reusable fallbacks. Matching and consumption share a lock so concurrent requests cannot consume a call twice.
func (*Handler) SetEnforceCallOrder ¶
SetEnforceCallOrder requires consumable calls in fixture order when enabled. Reusable fallbacks remain unordered. Changing this setting preserves the current step's consumption and failures.
func (*Handler) SetReusableFixtures ¶
SetReusableFixtures replaces test-wide fallback exchanges, such as metadata. They survive step transitions, may be matched repeatedly, and need not be consumed. Invalid fixtures leave the previous set intact.
type JSONMatcher ¶
JSONMatcher selects a literal object key or zero-based array index at each path segment. An explicit empty path selects the whole JSON body.
type Matcher ¶
type Matcher string
Matcher relaxes a selected request value without changing literal payloads.
const AnyString Matcher = "any_string"
AnyString requires a present string, including the empty string. It does not capture values or substitute them into later requests or responses.
type Matchers ¶
type Matchers struct {
Headers map[string]Matcher `yaml:"headers,omitempty"`
Query map[string]Matcher `yaml:"query,omitempty"`
JSON []JSONMatcher `yaml:"json,omitempty"`
}
Matchers override only the selected request values. Headers and query keys require exactly one value; JSON targets must exist in the sample body. Keeping these annotations outside the payload avoids reserved JSON keys.
type Request ¶
type Request struct {
Method string `yaml:"method"`
Path string `yaml:"path"`
Query map[string][]string `yaml:"query,omitempty"`
Headers map[string]string `yaml:"headers,omitempty"`
Body *Body `yaml:"body"`
Matchers Matchers `yaml:"matchers,omitempty"`
}
Request defines a complete signature; only listed headers are compared.