testserver

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 23 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 testserver starts a real motte server in the process of a caller's test.

Index

Constants

View Source
const DSNEnv = pgtest.DSNEnv

DSNEnv is the environment variable that Start reads when it gets no DSN.

Variables

This section is empty.

Functions

func Shared added in v0.22.0

func Shared(m *testing.M) int

Shared runs the tests of m with one server for the whole package, removes its state after the tests, and returns the exit code. Call it from TestMain as os.Exit(testserver.Shared(m)). It calls testcount.Run, so it replaces that call. Package returns the server, which starts on SQLite at its first call. Tests that share it must use a repository of their own, and read no events or subscriptions of other tests.

Types

type Faults added in v0.22.0

type Faults struct {
	// FinishLands runs before the leader records the results of a batch of lands.
	FinishLands func(ctx context.Context) error
	// ProtectedRefs runs before the server reads the protected ref patterns of a repository.
	ProtectedRefs func(ctx context.Context) error
	// BucketGet runs before the server reads the object at key, whole or in a range.
	BucketGet func(ctx context.Context, key string) error
	// BucketCreate runs before the server writes the object at key.
	BucketCreate func(ctx context.Context, key string) error
}

Faults makes the server fail or wait on the calls that tests need to break. A nil field changes nothing. A function runs before its call, and a non-nil error fails the call; a function that blocks holds the call.

type Limits added in v0.19.0

type Limits struct {
	// Object is the largest object that a put accepts, in bytes.
	Object int
	// Window bounds the JSON text that the decoder holds for one object, in bytes.
	Window int64
	// TreeFirst is the first reservation of a tree read, and TreeFixed the fixed part of every later one, in bytes.
	TreeFirst, TreeFixed int64
	// FetchLarge is the reservation above which a fetch takes one of the FetchSlots slots of large fetches.
	FetchLarge int64
	FetchSlots int
}

Limits lowers the size limits of one test, so that it crosses the same boundaries with small bodies. A zero field keeps the limit. The limits belong to the one server.

type Option added in v0.19.0

type Option func(*options)

Option changes how New starts a server.

func Required added in v0.19.0

func Required() Option

Required makes a missing PostgreSQL database fail the test instead of skipping it.

func Template added in v0.19.0

func Template(path string) Option

Template starts a SQLite server from a copy of the migrated database file at path. It has no effect on PostgreSQL.

func WithFaults added in v0.22.0

func WithFaults(f Faults) Option

WithFaults applies faults to the server and its replicas. Server.Meta and Server.Bucket stay without them.

func WithIdentity added in v0.22.0

func WithIdentity(v identity.Verifier, rules identity.Rules) Option

WithIdentity makes the server accept the identity verifier v and the access rules.

func WithLimits added in v0.19.0

func WithLimits(l Limits) Option

WithLimits lowers the size limits of the server for the test.

func WithPostgres added in v0.19.0

func WithPostgres(dsn string) Option

WithPostgres runs the server on a fresh schema of the PostgreSQL database at dsn. An empty dsn is read from DSNEnv, and then from the throwaway cluster of the package. Without a database the test skips, unless Required is set.

func WithReplicas added in v0.22.0

func WithReplicas(n int) Option

WithReplicas starts n more servers on the state and keys of the first, each with its own instance name. Their URLs are Server.Replicas.

type Server

type Server struct {
	URL string
	// Pool reaches the schema of the server, for a test that sets up a state no route can make. StartLocal leaves it nil.
	Pool *pgxpool.Pool
	// Replicas are the URLs of the extra servers that WithReplicas started on the state and keys of this one.
	Replicas []string
	// Meta, Bucket and Verifier are the state and the keys of the server, for a test that sets up a state no route can
	// make or runs a server with a configuration that no option sets.
	//
	// Deprecated: use WithReplicas and WithFaults. A caller outside this module still reads Meta.
	Meta     meta.Store
	Bucket   bucket.Store
	Verifier *grant.Verifier
	// Operator is the control-plane signer.
	Operator grant.Signer
	// Node is the node signer.
	Node grant.Signer
	// Expire is the expiry of the grants that the helpers mint.
	Expire time.Time
}

Server is a running store. Its control-plane key signs every scope. Its node key signs only node grants.

func Package added in v0.22.0

func Package(t testing.TB) *Server

Package returns the server that Shared serves. It fails the test when the package did not call Shared from TestMain.

func Start

func Start(t testing.TB, opts ...Option) *Server

Start runs a server on a temporary SQLite database and a temporary filesystem bucket, or on PostgreSQL with WithPostgres.

func StartLocal deprecated added in v0.6.0

func StartLocal(t testing.TB) *Server

StartLocal runs a server on a temporary SQLite database and a temporary filesystem bucket. It needs no other service and never skips. Pool is nil.

Deprecated: use Start, which runs on SQLite by default. A caller outside this module still calls StartLocal.

func (*Server) Client

func (s *Server) Client(token string, opts ...client.Option) *client.Client

Client returns a client that sends token on every call.

func (*Server) ImportGrant

func (s *Server) ImportGrant(t testing.TB, repo string) string

ImportGrant mints an import grant.

func (*Server) MergeGrant added in v0.6.0

func (s *Server) MergeGrant(t testing.TB, repo string) string

MergeGrant mints a merge grant that may move any ref.

func (*Server) Mint

func (s *Server) Mint(t testing.TB, signer grant.Signer, c grant.Claims) string

Mint signs c with signer and sets the expiry of the server when c has none.

func (*Server) NodeGrant

func (s *Server) NodeGrant(t testing.TB, workspace string, epoch uint64, repo string) string

NodeGrant mints a node grant with the node key.

func (*Server) OperatorGrant

func (s *Server) OperatorGrant(t testing.TB) string

OperatorGrant mints an operator grant.

func (*Server) ReadGrant

func (s *Server) ReadGrant(t testing.TB, repo string) string

ReadGrant mints a read grant.

func (*Server) WriteGrant added in v0.6.0

func (s *Server) WriteGrant(t testing.TB, repo string) string

WriteGrant mints a write grant.

Jump to

Keyboard shortcuts

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