comparison

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package comparison compares paired unary RPC responses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comparator

type Comparator struct {
	// contains filtered or unexported fields
}

Comparator shares one immutable script program across response comparisons. Only schema-plan replacement is synchronized; each comparison owns its evaluator.

func New

func New(ctx context.Context, config Config, log *slog.Logger) (*Comparator, error)

New constructs a response comparator from its parsed configuration.

func (*Comparator) Compare

func (c *Comparator) Compare(
	ctx context.Context,
	requestPath string,
	requestContentType string,
	reference Response,
	candidate Response,
) (result Result)

Compare compares one response pair without exposing response values in its result.

func (*Comparator) Configure

Configure activates the comparator against a reflected descriptor set.

func (*Comparator) MaxResponseBytes

func (c *Comparator) MaxResponseBytes() int

MaxResponseBytes returns the per-backend response capture limit.

type Config

type Config struct {
	// ComparisonScript is the JavaScript comparator file.
	ComparisonScript string `required:"" type:"existingfile" help:"JavaScript response comparator file."`
	// ComparisonTimeout limits one response comparison.
	ComparisonTimeout time.Duration `default:"1s" help:"Maximum duration of one response comparison."`
	// ComparisonMaxResponseBytes limits each captured backend response body.
	ComparisonMaxResponseBytes int `default:"1048576" help:"Maximum captured response bytes per backend."`
}

Config contains the command-line configuration for response comparison.

func NewConfig

func NewConfig() Config

NewConfig returns the default response comparison configuration.

func (Config) Validate

func (c Config) Validate() error

Validate checks that the comparison configuration is usable.

type Outcome

type Outcome string

Outcome describes whether a response pair could be compared and matched.

const (
	// Equivalent means the supported response pair matched.
	Equivalent Outcome = "equivalent"
	// Divergent means the supported response pair did not match.
	Divergent Outcome = "divergent"
	// Skipped means the request is outside the supported protocol scope.
	Skipped Outcome = "skipped"
	// Unable means a supported request could not be compared safely.
	Unable Outcome = "unable"
)

type Response

type Response struct {
	// StatusCode is the backend's HTTP status before RPC-level status handling.
	StatusCode int
	// Header includes response trailers promoted by the HTTP transport.
	Header http.Header
	// Body contains at most the configured capture limit.
	Body []byte
	// Overflow reports that Body is truncated and must not be compared.
	Overflow bool
}

Response is the captured result from one backend.

type Result

type Result struct {
	// contains filtered or unexported fields
}

Result is the value-safe result of comparing two responses.

func NewDifferenceResult

func NewDifferenceResult(differences ...string) Result

NewDifferenceResult constructs a divergent result without exposing response values.

func Resultf

func Resultf(outcome Outcome, format string, args ...any) Result

Resultf constructs a result with a printf-formatted reason.

func (Result) Differences

func (r Result) Differences() []string

Differences returns a copy of the divergent JSON paths.

func (Result) Outcome

func (r Result) Outcome() Outcome

Outcome returns the comparison classification.

func (Result) Reason

func (r Result) Reason() string

Reason returns why comparison was skipped or could not be completed.

Directories

Path Synopsis
Package javascript evaluates Spectre response comparator scripts.
Package javascript evaluates Spectre response comparator scripts.

Jump to

Keyboard shortcuts

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