rpctest

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 9 Imported by: ? 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 an app's RPC server on a temporary private socket for tests: the transport an app's own rpctest builds on. The app's rpctest builds its engine and services, lets a test replace any domain (Options.Services, frostmail's form), builds its router, and serves it with Serve; tests then dial the socket, or Pipe a connection served as another caller.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Socket

func Socket(t testing.TB) string

Socket returns a fresh socket path in a short private directory, which is removed when the test ends: a Unix socket path holds at most 108 bytes, more than a test's temp directory leaves.

Types

type Options

type Options[S any] struct {
	// Services, when set, edits the services before the router is built,
	// so a test can replace any domain with a fake.
	Services func(*S)
}

Options are what every app's rpctest options hold, with S the app's api.Services. An app embeds them in its own.

func (Options[S]) Edit

func (o Options[S]) Edit(s *S)

Edit applies Services to s.

type Run

type Run struct {
	// Socket is the server's private socket.
	Socket string
	// contains filtered or unexported fields
}

Run is a server under test.

func Serve

func Serve(t testing.TB, serve func(ctx context.Context, ln net.Listener) error) *Run

Serve listens on a fresh private socket (jsonrpc.Listen) and runs serve on it until the test ends or Stop. A serve that fails, or that does not return within 5 s of being stopped, fails the test. Off Linux, where jsonrpc.Listen serves no private socket, it skips the test.

func (*Run) Context

func (r *Run) Context() context.Context

Context ends when the server stops.

func (*Run) Dial

func (r *Run) Dial(t testing.TB) net.Conn

Dial connects to the socket; the connection closes when the test ends.

func (*Run) Pipe

func (r *Run) Pipe(t testing.TB, serve func(ctx context.Context, nc net.Conn)) net.Conn

Pipe serves one in-process connection with serve, as a listener that authenticated it would (lodge's /api, a development gateway), and returns the client's end. When the test ends, the client's end closes and serve is waited for.

func (*Run) Stop

func (r *Run) Stop()

Stop stops the server now, as a crash between requests would. The test's cleanup does the same; Stop is for restarting on the same data.

Jump to

Keyboard shortcuts

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