testutil

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func CanonicalJSON(v any) (string, error)

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

type Blocking struct {
	Ctx     context.Context
	Started chan<- struct{}
}

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.

func (Blocking) ReadAt

func (b Blocking) ReadAt([]byte, int64) (int, error)

ReadAt waits for the context.

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.

func (*DType) Paths

func (d *DType) Paths(prefix string) []string

Paths lists the column paths the oracle writes for a struct DType: each field, then, for a struct field, its own fields as dotted paths.

type EOFAtEnd

type EOFAtEnd struct {
	R    io.ReaderAt
	Size int64
}

EOFAtEnd is an io.ReaderAt over the Size bytes of R that returns io.EOF with the last bytes, as io.ReaderAt allows.

func (EOFAtEnd) ReadAt

func (e EOFAtEnd) ReadAt(p []byte, off int64) (int, error)

ReadAt reads from R, with io.EOF when the read reaches the end.

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

func LoadExpected(path string) (*Expected, error)

LoadExpected reads and parses a <file>.expected.json. Unknown keys are an error, so a change of the oracle's format cannot go unnoticed.

func (*Expected) Check

func (e *Expected) Check() error

Check returns what is wrong with the expected values: no column of the schema may lack an entry, and every entry has a hash.

type FailAt

type FailAt struct {
	R   io.ReaderAt
	Err error
	N   int64
	// contains filtered or unexported fields
}

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.

func (*FailAt) Calls

func (f *FailAt) Calls() int64

Calls is the number of calls so far.

func (*FailAt) ReadAt

func (f *FailAt) ReadAt(p []byte, off int64) (int, error)

ReadAt reads from R, except on call N.

type Field

type Field struct {
	DType *DType `json:"dtype"`
	Name  string `json:"name"`
}

Field is a named field of a struct DType.

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 NewHasher

func NewHasher() *Hasher

NewHasher starts a hash.

func (*Hasher) Bool

func (h *Hasher) Bool(v bool)

Bool adds the value of a bool.

func (*Hasher) Len

func (h *Hasher) Len(n int)

Len adds a length, a uint32 in little-endian: the prefix of a string, a binary and a list.

func (*Hasher) Null

func (h *Hasher) Null()

Null adds a null row, of any type.

func (*Hasher) Raw

func (h *Hasher) Raw(b []byte)

Raw adds the bytes of a value, as they are in the file.

func (*Hasher) Sum

func (h *Hasher) Sum() string

Sum is the hash so far, in hexadecimal.

func (*Hasher) Valid

func (h *Hasher) Valid()

Valid adds the validity byte of a valid row: its value follows, with Raw or Bool, or its fields, each with its own validity byte.

type Short

type Short struct {
	R   io.ReaderAt
	Max int
}

Short is an io.ReaderAt that returns at most Max bytes per call, and no error: a reader that has to be called again for the rest.

func (Short) ReadAt

func (s Short) ReadAt(p []byte, off int64) (int, error)

ReadAt reads at most Max bytes from R.

Jump to

Keyboard shortcuts

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