Documentation
¶
Overview ¶
Package compare finds every difference (drift) between a baseline response and a current one.
Index ¶
Constants ¶
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.
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.
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.
const DoctypePath = "!doctype"
DoctypePath is where a drift of the <!DOCTYPE> declaration is reported.
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).
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 ¶
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 Origin ¶
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 ¶
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 ¶
One compares a current response with its baseline. The rules that applied to a change count into the allowlist's Usage (allowlist.List.Track).
type Level ¶
type Level int
Level says how far a comparison goes; each level includes the previous ones.
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.