Help us shape the future of Go! Take the 2026 Go Developer Survey

compare

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package compare finds every difference (drift) between a baseline response and a current one.

Index

Constants

View Source
const (
	KindNotCaptured   = "not-captured"
	KindStatus        = "status"
	KindHeaderMissing = "header-missing"
	KindHeaderExtra   = "header-extra"
	KindHeaderValue   = "header-value"
	KindKeyMissing    = "key-missing"
	KindKeyExtra      = "key-extra"
	KindKeyOrder      = "key-order"
	KindArrayLength   = "array-length"
	KindType          = "type"
	KindNumberLiteral = "number-literal"
	KindFormat        = "format"
	KindValue         = "value"
	KindEncoding      = "encoding"
	KindBody          = "body"
	KindSideEffect    = "side-effect"
)

Drift kinds. The names are stable: reports and CI rely on them.

View Source
const (
	KindElementMissing   = "element-missing"
	KindElementExtra     = "element-extra"
	KindElementOrder     = "element-order"
	KindAttributeMissing = "attribute-missing"
	KindAttributeExtra   = "attribute-extra"
	KindAttributeValue   = "attribute-value"
	KindText             = "text"
	KindDoctype          = "doctype" // the document type declaration, at DoctypePath
)

Drift kinds of an HTML body.

View Source
const (
	KindExit   = "exit-code" // a command step ended with another exit code
	KindRepeat = "repeat"    // the statuses of a request sent several times
	KindCell   = "cell"      // a cell of a CSV or XLSX body
	// The number format and the formula of an XLSX cell; its type is a
	// drift of KindType.
	KindCellFormat  = "cell-format"
	KindCellFormula = "cell-formula"

	// A worksheet of an XLSX body, matched by the name the workbook gives
	// it: missing now, new, or the worksheets both have in another order.
	KindSheetMissing = "sheet-missing"
	KindSheetExtra   = "sheet-extra"
	KindSheetOrder   = "sheet-order"
)

Drift kinds of command steps, repeated requests and spreadsheet bodies.

View Source
const DoctypePath = "!doctype"

DoctypePath is where a drift of the <!DOCTYPE> declaration is reported.

View Source
const FlightPath = "self.__next_f"

FlightPath is where the React Server Components payload of a Next.js app router page (self.__next_f.push) is compared: FlightPath + a JSON path, one key per payload row (self.__next_f$.0.b is the build id).

View Source
const KindItemOrder = "item-order"

KindItemOrder is a changed order of the items of an array paired by key (allowlist arrays:), unless the rule says any_order.

Variables

View Source
var FastPaths = true

FastPaths turns on the shortcuts that only save work: rules narrowed to the request, identical parts of two bodies passed over and objects with the same keys paired by position. Tests turn it off to check that the result stays the same.

Functions

func AnyItem

func AnyItem(path string) string

AnyItem writes every array index and item key of a path as [*].

func Origin

func Origin(raw string) (string, error)

Origin returns the origin of an http or https URL: scheme://host[:port] in lower case, without the default port of the scheme.

func Places

func Places(s Side, allow *allowlist.List, id string, fn func(kind PlaceKind, path string) bool)

Places names every place of a body that a rule of the allowlist can reach, with the path a drift there would have (allowlist check uses it to find rules that reach nothing). The body is read as body() reads it: an HTML page, else a spreadsheet, else JSON; a body that is not JSON is also the place allowlist.RawPath. The items of an array that an array rule of allow pairs by key for the request id are named by their key. fn returns false to stop.

Types

type Drift

type Drift struct {
	Request  string `json:"request"`
	Kind     string `json:"kind"`
	Where    string `json:"where"`
	Baseline string `json:"baseline,omitempty"`
	Current  string `json:"current,omitempty"`
	// Texts holds a changed scalar or single header value as the allowlist
	// sees it (strings without quotes), for proposing a format.
	Texts [2]string `json:"-"`
	// Values holds the values of a changed header (baseline, current).
	Values [2][]string `json:"-"`
}

Drift is one difference.

func One

func One(id string, base, cur Side, allow *allowlist.List, level Level) []Drift

One compares a current response with its baseline. The rules that applied to a change count into the allowlist's Usage (allowlist.List.Track).

func OneNotes

func OneNotes(id string, base, cur Side, allow *allowlist.List, level Level) ([]Drift, []string)

OneNotes is One with the notes on how the comparison went where that is not a drift: an array the allowlist pairs by key whose items had to be paired by position.

func (Drift) Signature

func (d Drift) Signature() string

Signature groups drifts that come from the same change, for example one date format change across hundreds of list items.

type Level

type Level int

Level says how far a comparison goes; each level includes the previous ones.

const (
	LevelStatus Level = iota // status code only
	LevelShape               // + header names, keys, key order, nesting, array lengths
	LevelTypes               // + the type of every value
	LevelValues              // + exact values, header values and body bytes
)

func ParseLevel

func ParseLevel(s string) (Level, error)

ParseLevel reads a level name.

func (Level) String

func (l Level) String() string

type PlaceKind

type PlaceKind int

PlaceKind is what a rule of the allowlist can reach in a body.

const (
	PlaceValue PlaceKind = iota // a JSON scalar, a text or an attribute of a page
	PlaceArray                  // a JSON array (any_length)
	PlaceCell                   // a cell of a spreadsheet
	PlaceBody                   // the whole body of a response that is not JSON (allowlist.RawPath)
)

type Side

type Side struct {
	Record *snapshot.Record
	Body   []byte
	// NoBody marks a side whose body is not available (a private body not
	// on this machine): everything but the body is compared.
	NoBody bool
	// Origins are the side's own origins (scheme://host[:port]): the one it
	// was captured from and its aliases. When the two sides have different
	// ones, all of them are taken as the same origin (origin.go).
	Origins []string
}

Side is one response with its body.

Jump to

Keyboard shortcuts

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