rpctest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 19 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 rpctest runs a real notesd API server (store, blobs, broker, vaults, engine and rpcserver) on a temporary socket, for tests of clients such as notesctl. The socket, the serving goroutine and its stop are lodge's kit's (github.com/frostyard/lodge/kit/rpctest).

Index

Constants

View Source
const Name = "notesd rpctest"

Name is what the test server reports from rpc.hello.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	kitrpctest.Options[api.Services]
	// Log receives the server's logs; nil discards them.
	Log *slog.Logger
	// DataDir holds the database; empty means a fresh temporary directory.
	// Reusing one after Stop restarts notesd on the same data.
	DataDir string
	// Now, when set, is the clock for stored timestamps.
	Now func() time.Time
	// Vault tunes the vaults' actors (intervals, batch size); its DB,
	// Blobs, Log, Publish and, when Now is set, Now are filled in.
	Vault vault.Config
	// HubListen serves the hub's endpoints on a loopback port, at
	// Server.HubURL, as notesd --hub does; HubAddr, when set, is the
	// address, so a restarted hub keeps its URL.
	HubListen bool
	HubAddr   string
	// Crash is the simulation's crash points (vault.Config.Crash and its
	// syncer and hub counterparts).
	Crash func(point string) bool
	// Syncer tunes the device's sync loops (quiet periods, backoff, the
	// device's name); its stores, broker, secrets, log and, when Now is
	// set, Now are filled in.
	Syncer syncer.Config
}

Options configure a test server. Their Services, when set, edit the engine's services before the router is built, so a client's tests can serve a fake domain.

type Server

type Server struct {
	Socket string
	Run    *kitrpctest.Run
	DB     *store.DB
	Blobs  *blobs.Store
	Broker *events.Broker
	Vaults *vault.Manager
	RPC    *rpcserver.Server
	// Router serves every domain; pass it to RPC.ServeConn to test a
	// connection of another caller kind.
	Router *api.Router
	// Hub and Syncer are this notesd's hub role and sync loops; Secrets
	// keeps its device tokens, in a file. HubURL is set with HubListen.
	Hub     *hub.Hub
	Syncer  *syncer.Syncer
	Secrets secrets.Store
	HubURL  string
	// contains filtered or unexported fields
}

Server is a running test server; it stops when the test ends.

func Start

func Start(t testing.TB) *Server

Start runs a server with default options.

func StartWith

func StartWith(t testing.TB, o Options) *Server

StartWith runs a server with a fresh database, on a socket of its own (SocketPath).

func (*Server) Dial

func (s *Server) Dial(t testing.TB) *api.Client

Dial connects and completes rpc.hello; the client closes when the test ends.

func (*Server) DialAs

func (s *Server) DialAs(t testing.TB, id api.Identity) *api.Client

DialAs connects as a connection its listener authenticated as id (a session or an agent behind lodge, a device) over an in-process pipe, and completes rpc.hello; the client closes when the test ends.

func (*Server) Stop

func (s *Server) Stop()

Stop shuts the server down now, as a crash between transactions would: the socket closes and the database is closed. The test's cleanup does the same; Stop is for restarting on the same DataDir.

Jump to

Keyboard shortcuts

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