server

package
v0.0.0-...-85425c5 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package server hosts many sandboxes in one process and exposes a small control API for driving them.

One process rather than a container per provider: booting eight fakes should cost milliseconds and a few megabytes, because in CI it happens on every commit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server multiplexes sandboxes.

func New

func New() *Server

New returns an empty server. All sandboxes share one clock, so advancing time moves every provider together — which is what a developer means by "skip forward a month".

func (*Server) Clock

func (s *Server) Clock() *clock.Clock

Clock returns the shared clock.

func (*Server) HasFixture

func (s *Server) HasFixture(recipe, fixture string) bool

HasFixture reports whether a mounted recipe ships a fixture.

func (*Server) Mount

func (s *Server) Mount(name string, seed int64, fixture string) error

Mount boots a Recipe by name and adds it to the server.

func (*Server) Names

func (s *Server) Names() []string

Names returns the mounted recipe names.

func (*Server) Restore

func (s *Server) Restore(snapshot Snapshot) error

Restore applies a snapshot to every recipe it names.

Recipes in the snapshot that are not mounted are reported rather than ignored, because a partially restored sandbox that claims success is worse than a refusal.

func (*Server) Sandbox

func (s *Server) Sandbox(name string) (*runtime.Sandbox, bool)

Sandbox returns a mounted sandbox.

func (*Server) SeedRecipe

func (s *Server) SeedRecipe(recipe, fixture string) error

SeedRecipe loads a fixture into one mounted recipe.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP routes a request to the right sandbox.

Two addressing schemes are supported. The path prefix (http://localhost:4600/stripe/v1/customers) works everywhere with no DNS setup, which matters because it is what a developer pastes into a base URL. The host prefix (http://stripe.cauldron.test/v1/customers) is nicer once local domains exist.

func (*Server) Snapshot

func (s *Server) Snapshot() Snapshot

Snapshot captures every mounted sandbox.

type Snapshot

type Snapshot struct {
	Version int                         `json:"version"`
	Clock   time.Time                   `json:"clock"`
	Recipes map[string]runtime.Snapshot `json:"recipes"`
}

Snapshot is the state of every sandbox on this server, plus the shared clock.

It is taken across all recipes rather than one, because a bug worth capturing usually spans providers: the payment succeeded, the order did not ship, and the state that proves it lives in two sandboxes at once.

Jump to

Keyboard shortcuts

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