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 ¶
- type Server
- func (s *Server) Clock() *clock.Clock
- func (s *Server) HasFixture(recipe, fixture string) bool
- func (s *Server) Mount(name string, seed int64, fixture string) error
- func (s *Server) Names() []string
- func (s *Server) Restore(snapshot Snapshot) error
- func (s *Server) Sandbox(name string) (*runtime.Sandbox, bool)
- func (s *Server) SeedRecipe(recipe, fixture string) error
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) Snapshot() Snapshot
- type Snapshot
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) HasFixture ¶
HasFixture reports whether a mounted recipe ships a fixture.
func (*Server) Restore ¶
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) SeedRecipe ¶
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.
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.