Documentation
¶
Overview ¶
Package httpfixture replays HTTP exchanges without simulating remote state.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PreserveMatchers ¶
PreserveMatchers carries author-selected volatility annotations to refreshed calls using the existing matching rules, never call indices. Interleaving and extra reads therefore cannot attach an annotation to another operation. Unmatched annotations fail refresh instead of being silently lost.
Types ¶
type Body ¶
type Body struct {
JSON any `yaml:"json,omitempty"`
Text *string `yaml:"text,omitempty"`
Base64 *string `yaml:"base64,omitempty"`
Multipart []MultipartPart `yaml:"multipart,omitempty"`
}
Body selects semantic JSON, exact UTF-8 text, exact binary bytes encoded as base64, or multipart form parts. A nil *Body means no HTTP body.
func (Body) MarshalYAML ¶
MarshalYAML preserves an explicit JSON null instead of emitting an empty body mapping. The other representations also retain intentionally empty bytes.
type CaptureTransport ¶
type CaptureTransport struct {
// contains filtered or unexported fields
}
CaptureTransport observes HTTP at the same boundary used by replay. It does not authenticate, retry, choose hosts, or write files; those belong to callers. Response bodies are buffered and restored before the SDK sees them.
func NewCaptureTransport ¶
func NewCaptureTransport(base http.RoundTripper) *CaptureTransport
NewCaptureTransport wraps the caller's transport. Snapshots contain API payloads in memory; the owning recorder must sanitize them before persistence.
func (*CaptureTransport) Snapshot ¶
func (c *CaptureTransport) Snapshot() ([]CapturedStep, error)
Snapshot returns an independent copy so normalization cannot race with capture or alter a later snapshot. An incomplete exchange never becomes a fixture.
func (*CaptureTransport) StartStep ¶
func (c *CaptureTransport) StartStep(label string) error
StartStep refuses transitions during a request so a late reply cannot be attributed to the next step. Capture failures are permanent for this session.
func (*CaptureTransport) Verify ¶
func (c *CaptureTransport) Verify() error
type CapturedStep ¶
CapturedStep retains dispatch order, even when concurrent replies finish in another order. Recording that order does not opt a test into ordered replay.
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 MultipartPart ¶
type MultipartPart struct {
Name string `yaml:"name"`
Filename string `yaml:"filename,omitempty"`
Headers map[string]string `yaml:"headers,omitempty"`
Body *Body `yaml:"body"`
}
MultipartPart describes one form field or file. Part order and the transport boundary are ignored; names, filenames, bytes and listed headers remain exact.
func (*MultipartPart) UnmarshalYAML ¶
func (p *MultipartPart) UnmarshalYAML(node *yaml.Node) error
UnmarshalYAML keeps strict field checking inside the custom Body decoder.
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.