comparison

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package comparison normalises payloads with scripts, then diffs or hashes them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ScriptsDir holds the normaliser scripts, which are all loaded as one set.
	ScriptsDir string `` /* 165-byte string literal not displayed */
	// Schema types every payload the scripts register for.
	Schema schema.Config `embed:""`
	// ComparisonTimeout limits one response comparison.
	ComparisonTimeout time.Duration `default:"1s" help:"Maximum duration of one response comparison."`
}

Config contains the command-line configuration for scripts and 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 Hash added in v0.25.0

type Hash [sha256.Size]byte

Hash identifies a payload by its identity and normalised content, so equivalent payloads share a hash.

type Scripts added in v0.25.0

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

Scripts is one immutable set of normaliser scripts and the schema they were checked against. It is safe for concurrent use.

func New

func New(ctx context.Context, config Config) (*Scripts, error)

New loads every script in the configured directory and checks that each declared endpoint type exists.

func (*Scripts) Compare added in v0.25.0

func (s *Scripts) Compare(ctx context.Context, typeName Option[schema.TypeRef], reference, candidate any) (differences []string, err error)

Compare normalises both payloads as typeName and returns the paths at which they differ. Untyped payloads are compared without normalisers.

func (*Scripts) Endpoints added in v0.25.0

func (s *Scripts) Endpoints() []javascript.Endpoint

Endpoints returns every declared endpoint, ingress first, in declaration order.

func (*Scripts) Hash added in v0.25.0

func (s *Scripts) Hash(ctx context.Context, identity string, typeName Option[schema.TypeRef], side string, payload any) (Hash, error)

Hash returns SHA-256 over identity and the canonical JSON of the normalised payload. side only labels log records.

func (*Scripts) NormaliseResponse added in v0.43.0

func (s *Scripts) NormaliseResponse(ctx context.Context, rule javascript.Rule, status int, body Option[any]) (Option[int], Option[any], error)

NormaliseResponse applies a rule's normaliser to one response. A None status or body is not compared, and a returned body must still be the rule's type.

func (*Scripts) Rules added in v0.43.0

func (s *Scripts) Rules() []javascript.Rule

Rules returns the ingress rules in declaration order.

func (*Scripts) Schema added in v0.25.0

func (s *Scripts) Schema() *schema.Schema

Schema returns the payload types the scripts were checked against.

func (*Scripts) SelectRule added in v0.43.0

func (s *Scripts) SelectRule(ctx context.Context, rules []javascript.Rule, request javascript.Request, status int) (Option[javascript.Rule], error)

SelectRule returns the first rule that selects a response. rules must be in declaration order, and the request must match each rule's pattern, if it has one.

Directories

Path Synopsis
Package javascript evaluates Spectre payload normaliser scripts.
Package javascript evaluates Spectre payload normaliser scripts.

Jump to

Keyboard shortcuts

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