testserver

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 5 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 testserver is the "Bookstore" API used by the component tests of apitest. Its spec is testdata/bookstore.yaml. Each switch in Faults builds in exactly one kind of error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Faults

type Faults struct {
	WrongStatus        bool // POST /authors answers 200 instead of 201
	UndocumentedStatus bool // GET /books/{id} answers 202
	SchemaViolation    bool // GET /books/{id} returns authorId as a string
	ExampleMismatch    bool // POST /authors returns a different name than it stores
	Slow               bool // GET /authors answers after 30 s (or when the request ends)
	DropOnUpdate       bool // PUT /books/{id} answers 200 but does not store the title
	DeleteNoop         bool // DELETE /reviews/{id} answers 204 but does not delete
	FailCreateAuthor   bool // POST /authors with a valid body answers 500
	DropShelfName      bool // PUT /shelves/{code} stores the new code but not the name
	IgnoreAuth         bool // requests without token (or api_key) are accepted
	IgnoreSignature    bool // any bearer token is accepted, also manipulated ones
	IgnoreRoles        bool // the reader token may write
	// AsyncUpdate makes PUT /authors/{id} visible only after this many GETs
	// of the author (eventual consistency, FR-VERIFY-06); 0 applies at once.
	AsyncUpdate int
}

Faults switch on deliberate errors.

type Server

type Server struct {
	Tokens  []string // accepted bearer tokens with full rights
	Readers []string // accepted bearer tokens that may only read (403 on writes)
	APIKey  string   // expected api_key query parameter
	Faults  Faults
	// contains filtered or unexported fields
}

Server is the Bookstore API. It is an http.Handler serving under /v1.

func New

func New(token, apiKey string, f Faults) *Server

New returns a Bookstore with one seed author (ID 1).

func (*Server) ServeHTTP

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

Jump to

Keyboard shortcuts

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