extractors

package
v0.71.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 9 Imported by: 0

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

View Source
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) ExtractText added in v0.64.0

func (e BodyExtractor) ExtractText(ctx ResponseContext) (any, error)

ExtractText returns the body as received when it parsed into a JSON object or array, so a string operator matches the wire text instead of a Go map printout. A scalar body keeps its parsed value.

func (BodyExtractor) GetType

func (e BodyExtractor) GetType() spi.ExtractorType

type HeaderAccessor

type HeaderAccessor interface {
	GetHeader(key string) string
	Headers() http.Header
}

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

type ParsedBodyReader interface {
	GetParsedBody() any
	GetRawBody() []byte
}

ParsedBodyReader provides access to pre-parsed body (JSON, XML, etc.)

type QueryParamAccessor added in v0.64.0

type QueryParamAccessor interface {
	GetQueryParam(name string) (string, bool)
}

QueryParamAccessor provides access to the query parameters of a received request.

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 TextExtractor added in v0.64.0

type TextExtractor interface {
	ExtractText(ctx ResponseContext) (any, error)
}

TextExtractor is an extractor whose value has a text form that differs from its structured value. String operators compare against the text form.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL