testfixture

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package testfixture implements the three controlled REST APIs that sit behind the gateway in its security, proxy, concurrency and crash regressions: orders, inventory and reports. Each serves synthetic data held in memory and records independent request receipts. Once its receipt log is full it refuses further operations. Receipts, state and reset use a control listener that requires a secret. The orders API also enforces object ownership with the subject and roles that the gateway forwards. Fetch's application services are implemented by the parent services package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, s *Service, listen, control string, secret []byte) error

Run serves the API and control listeners until ctx is cancelled. Both addresses must be literal loopback addresses, so neither is reachable from another host.

Types

type Catalogue

type Catalogue struct {
	Version  string   `json:"version"`
	Roles    []string `json:"roles"`
	Fixtures []struct {
		Service    string `json:"service"`
		Version    string `json:"version"`
		SeedSHA256 string `json:"seed_sha256"`
	} `json:"fixtures"`
	Operations []struct {
		ID     string   `json:"id"`
		API    string   `json:"api"`
		Method string   `json:"method"`
		Target string   `json:"target"`
		Auth   string   `json:"auth"`
		Body   bool     `json:"body"`
		Roles  []string `json:"roles"`
	} `json:"operations"`
	Subjects  []Subject  `json:"subjects"`
	Scenarios []Scenario `json:"scenarios"`
}

Catalogue is the decoded truth catalogue.

func LoadCatalogue

func LoadCatalogue() (Catalogue, error)

LoadCatalogue decodes the embedded catalogue, rejecting unknown fields.

type Receipt

type Receipt struct {
	Seq           int       `json:"seq"`
	Time          time.Time `json:"time"`
	RequestID     string    `json:"request_id"`
	Generation    string    `json:"generation"`
	Method        string    `json:"method"`
	Target        string    `json:"target"`
	Operation     string    `json:"operation"`
	Status        int       `json:"status"`
	Effect        string    `json:"effect,omitempty"`
	Authorization bool      `json:"authorization"`
	Subject       string    `json:"subject,omitempty"` // X-Gateway-Subject as received
	Roles         string    `json:"roles,omitempty"`   // X-Gateway-Roles as received
	BodyBytes     int       `json:"body_bytes"`
	BodySHA256    string    `json:"body_sha256,omitempty"`
}

Receipt is the fixture's own record of one request it received, written whether or not an operation matched.

type Scenario

type Scenario struct {
	Name          string          `json:"name"`
	Subject       string          `json:"subject,omitempty"`
	Operation     string          `json:"operation"`
	Method        string          `json:"method"`
	Path          string          `json:"path"`
	Body          json.RawMessage `json:"body,omitempty"`
	GatewayStage  string          `json:"gateway_stage,omitempty"`
	GatewayStatus int             `json:"gateway_status,omitempty"`
	Status        int             `json:"status"`
	ChangesState  bool            `json:"changes_state"`
	Effect        string          `json:"effect,omitempty"`
	Response      json.RawMessage `json:"response,omitempty"`
}

Scenario is one step of the replay sequence. Steps depend on the state left by earlier steps, so they run in order from the seed. Subject is the caller, empty for a public operation. Status and the fields after it are the fixture's own outcome. GatewayStage, when set, names the gateway stage that must refuse the step with GatewayStatus before it reaches any fixture.

type Service

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

Service is one running fixture API.

func New

func New(name string) (*Service, error)

New returns the named fixture with its seed data loaded.

func (*Service) Control

func (s *Service) Control(secret []byte) http.Handler

Control returns the privileged handler for receipts, state and reset. It must be served only on a listener that the gateway's clients cannot reach.

func (*Service) ServeHTTP

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

ServeHTTP runs the matching operation and records the receipt. Every request is recorded unless the receipt log is full; then it is refused without a receipt. A missing receipt alone does not establish non-arrival.

type State

type State struct {
	Service  string          `json:"service"`
	Version  string          `json:"version"`
	Instance string          `json:"instance"`
	SHA256   string          `json:"sha256"`
	Data     json.RawMessage `json:"data"`
}

State is the control view of a fixture's data.

type Subject

type Subject struct {
	ID     string   `json:"id"`
	Status string   `json:"status"`
	Roles  []string `json:"roles"`
}

Subject is a controlled caller identity and the roles it is meant to hold. A disabled subject must be refused whatever its roles.

Jump to

Keyboard shortcuts

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