servertest

package
v0.26.1 Latest Latest
Warning

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

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

Documentation

Overview

Package servertest drives a running OpenVaultDB HTTP API the way a client does, so that a server, or a service built on the library such as the cloud, can prove in its own tests that every collection of a mount answers.

EveryCollection reads the metadata of one database and runs a fixed battery of relational TugQL reads on each collection it lists: a bounded read, an unbounded streamed read, a deterministic order, an order by each field, an equality filter on each scalar field of a sampled row, an offset page, and the refusal of values an integer column cannot hold. It returns a Report; a test asserts on Report.Failures, or calls RequireEveryCollection.

Index

Constants

View Source
const (
	KindPlain        = "plain"        // {from, limit: 5} answers 200
	KindNoLimit      = "nolimit"      // {from} streamed answers complete or query_budget_exceeded
	KindOrder        = "order"        // ordered by the primary key, else by every field
	KindOrderEach    = "orderEach"    // ordered by each field, descending
	KindFilter       = "filter"       // == on each scalar field of a sampled row finds a row
	KindOffset       = "offset"       // ordered page with an offset
	KindBadInteger   = "badInteger"   // a value an integer column cannot hold is a 400
	KindExactInteger = "exactInteger" // an exact integer above 2^53 is accepted on a bigint column
)

Check kinds, as Check.Kind and the keys of Report.Matrix spell them.

Variables

This section is empty.

Functions

This section is empty.

Types

type Check

type Check struct {
	Database   string
	Collection string // the collection ID the metadata lists
	Schema     string // the source schema, for a native PostgreSQL collection
	Name       string // the source relation name, else the collection ID
	Kind       string
	Detail     string // the field or value the request is about, if any
	Status     int    // the HTTP status, 0 when no response was read
	Passed     bool
	Message    string // why a check failed
}

Check is the outcome of one request of the battery.

func (Check) String

func (c Check) String() string

type Options

type Options struct {
	// Client sends the requests; nil is http.DefaultClient.
	Client *http.Client
	// Header is added to every request, for example an Authorization header.
	Header http.Header
	// Expected reports a failed check as one the caller documents and expects; it
	// is then counted as passed, with its message kept. Nil expects none.
	Expected func(Check) bool
	// Collections, when not empty, limits the battery to these collection IDs.
	Collections []string
}

Options tunes EveryCollection. The zero value uses http.DefaultClient.

type Report

type Report struct {
	Database    string
	Collections int
	Checks      []Check
}

Report is the outcome of the battery on one database.

func EveryCollection

func EveryCollection(ctx context.Context, baseURL, databaseID string, opts Options) (Report, error)

EveryCollection runs the battery on every collection databaseID lists at baseURL (the origin of the API, without /v1). The error is the failure to read the metadata or a cancelled context; a failed request is a failed Check.

func RequireEveryCollection

func RequireEveryCollection(t testing.TB, ctx context.Context, baseURL, databaseID string, opts Options) Report

RequireEveryCollection runs EveryCollection, logs the matrix and fails t on an error or on any failed check, listing each.

func (Report) Failures

func (r Report) Failures() []Check

Failures returns the checks that did not pass, in the order they ran.

func (Report) Matrix

func (r Report) Matrix() map[string]int

Matrix counts the checks by kind and outcome, as "<kind>:pass" and "<kind>:fail".

func (Report) MatrixString

func (r Report) MatrixString() string

MatrixString is Matrix as one sorted line.

Jump to

Keyboard shortcuts

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