Documentation
¶
Overview ¶
Package extractors pulls a value out of a node's result for assertions and outputs: jsonPath/xmlPath into a parsed body, the raw body, an HTTP status code, a header.
One typed extractor per type behind the AnyExtractor interface, dispatched through a registry: RegisterExtractor binds an spi.ExtractorType to a factory that decodes the extractor's JSON config into its concrete struct, and UnmarshalExtractor peeks the wire "type" field to pick the factory. Adding an extractor = a new struct + RegisterExtractor from an init() — no switch to edit. Built-ins register in builtin.go; the HTTP-only ones (statusCode/header) register from the extractors/http subpackage.
Extract returns any: the extracted value's type is only known at runtime (a JSONPath into an arbitrary body), so this is the deliberate untyped boundary.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotImplemented = errors.New("extractor not implemented")
Functions ¶
func RegisterExtractor ¶
func RegisterExtractor(extType spi.ExtractorType, factory func([]byte) (AnyExtractor, error))
RegisterExtractor registers a factory function for an extractor type.
Types ¶
type AnyExtractor ¶
type AnyExtractor interface {
Extract(ctx ResponseContext) (any, error)
GetType() spi.ExtractorType
}
func UnmarshalExtractor ¶
func UnmarshalExtractor(data []byte) (AnyExtractor, error)
UnmarshalExtractor creates an Extractor from raw JSON via the registry. Built-in extractors register in builtin.go; statusCode/header in the http package — so this is a pure lookup with no per-type switch to edit.
type BodyExtractor ¶
type BodyExtractor struct {
}
BodyExtractor extracts the entire response body. It can be used to capture the complete response as a value.
func (BodyExtractor) Extract ¶
func (e BodyExtractor) Extract(ctx ResponseContext) (any, error)
func (BodyExtractor) GetType ¶
func (e BodyExtractor) GetType() spi.ExtractorType
type HeaderAccessor ¶
HeaderAccessor provides access to HTTP headers.
type JSONPathExtractor ¶
type JSONPathExtractor struct {
Path string `json:"path"`
}
JSONPathExtractor extracts values from JSON using JSONPath expressions (RFC 9535).
func (JSONPathExtractor) Extract ¶
func (e JSONPathExtractor) Extract(ctx ResponseContext) (any, error)
func (JSONPathExtractor) GetType ¶
func (e JSONPathExtractor) GetType() spi.ExtractorType
type ParsedBodyReader ¶
ParsedBodyReader provides access to pre-parsed body (JSON, XML, etc.)
type ResponseContext ¶
type ResponseContext interface {
// All extractors can query what capabilities are available
HasCapability(capability string) bool
}
ResponseContext is the main context interface that all extractors receive. Concrete implementations can opt-in to specific capability interfaces.
func NewResponseContext ¶
func NewResponseContext( resp *http.Response, rawBody []byte, parsedBody any, ) ResponseContext
NewResponseContext creates a new ResponseContext from an HTTP response.
func NewValueResponseContext ¶
func NewValueResponseContext(value any) ResponseContext
NewValueResponseContext builds a ResponseContext backed by an arbitrary value. The value is exposed as the parsed body (GetParsedBody) and its JSON encoding as the raw body (GetRawBody). Status is 0 and headers are empty — only the body / parsed_body capabilities are advertised, which is what the jsonPath and body extractors need.
type StatusReader ¶
type StatusReader interface {
GetStatus() int
}
StatusReader provides access to HTTP status code.
type XMLPathExtractor ¶
type XMLPathExtractor struct {
Path string `json:"path"`
}
XMLPathExtractor extracts values from XML using XPath expressions.
func (XMLPathExtractor) Extract ¶
func (e XMLPathExtractor) Extract(_ ResponseContext) (any, error)
func (XMLPathExtractor) GetType ¶
func (e XMLPathExtractor) GetType() spi.ExtractorType