Documentation
¶
Overview ¶
Package testutil holds test-only helpers. Nothing outside _test.go files imports it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CanonicalJSON ¶
CanonicalJSON renders a Variant value as the canonical JSON of docs/testing.md, which the hash of a Variant column is taken over. The value is what Column.Variant returns: nil, bool, int64, float64, string, []byte, time.Time, a decimal (a fmt.Stringer), []any or map[string]any.
There is no space, the keys of an object are sorted by their bytes, an integer is its digits and a float its 17 significant digits ("%.17g", with ".0" added when that looks like an integer; NaN, Infinity and -Infinity are bare). A string escapes only the quote, the backslash and the control characters (\u00XX). A binary is {"$binary":"<hex>"}, a time is {"$time":"<UTC, RFC 3339, as many fraction digits as needed>"} and a decimal is {"$decimal":"<text>"}.
Types ¶
type Blocking ¶
Blocking is an io.ReaderAt whose calls block until Ctx is done, then return its error. Its Started channel, when set, gets a value at each call that finds room in it.
type Column ¶
type Column struct {
// SHA256 is the canonical hash.
SHA256 *string `json:"sha256"`
SampleError string `json:"sample_error,omitempty"`
First []string `json:"first"`
Last []string `json:"last"`
Nulls int64 `json:"nulls"`
}
Column is what the oracle read for one column, or one nested struct field (dotted path).
type DType ¶
type DType struct {
Kind string `json:"kind"`
Ptype string `json:"ptype,omitempty"`
ExtID string `json:"ext_id,omitempty"`
ExtMetadata string `json:"ext_metadata,omitempty"`
Element *DType `json:"element,omitempty"`
Key *DType `json:"key,omitempty"`
Value *DType `json:"value,omitempty"`
Storage *DType `json:"storage,omitempty"`
Fields []*Field `json:"fields,omitempty"`
Precision int `json:"precision,omitempty"`
Scale int `json:"scale,omitempty"`
Size int `json:"size,omitempty"`
Nullable bool `json:"nullable"`
KeysSorted bool `json:"keys_sorted,omitempty"`
}
DType is a node of the DType tree the oracle wrote. Only the fields of its Kind are set.
type EOFAtEnd ¶
EOFAtEnd is an io.ReaderAt over the Size bytes of R that returns io.EOF with the last bytes, as io.ReaderAt allows.
type Expected ¶
type Expected struct {
Columns map[string]Column `json:"columns"`
Encodings []string `json:"encodings"`
Schema DType `json:"schema"`
Rows int64 `json:"rows"`
}
Expected is the content of a <file>.expected.json.
func LoadExpected ¶
LoadExpected reads and parses a <file>.expected.json. Unknown keys are an error, so a change of the oracle's format cannot go unnoticed.
type FailAt ¶
FailAt is an io.ReaderAt whose call N (from 1) fails with Err. The other calls go to R. It is safe for concurrent use.
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
Hasher computes the canonical hash of docs/testing.md, section 1, the one the oracle computes too: for each row, one validity byte, then the value when the row is valid. The caller walks the rows in order and tells the hasher about each one. Integers and floats are their little-endian bytes, a bool is one byte, a struct is its fields in order, each one a row of its own type. A string, a binary and a list are a length (Len) then the bytes or the elements, a fixed-size list and a UUID have no length, a decimal is 16 or 32 bytes.
func (*Hasher) Len ¶
Len adds a length, a uint32 in little-endian: the prefix of a string, a binary and a list.