Documentation
¶
Overview ¶
Package fixture serves committed site trees over httptest.
Tests never talk to the live network. Each fixture lives under testdata/fixtures/<name>/ with a manifest.json that maps paths to files and optional request conditions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Get ¶
func Get(t testing.TB, s *Server, path, ua, accept string, extra http.Header) (int, http.Header, []byte)
Get issues a request against s and returns status, headers, body.
func ModuleRoot ¶
ModuleRoot walks up from the working directory to go.mod.
Types ¶
type Page ¶
type Page struct {
Path string `json:"path"`
File string `json:"file"`
ContentType string `json:"content_type"`
Headers map[string]string `json:"headers,omitempty"`
When *When `json:"when,omitempty"`
Status int `json:"status,omitempty"`
Redirect string `json:"redirect,omitempty"`
}
Page is one path-to-file mapping. Pages are tried in order; the first whose When matches the request wins.
type RequestLog ¶
type RequestLog struct {
Method string
Path string
UserAgent string
Accept string
Signature string
SigInput string
SigAgent string
Header http.Header
}
RequestLog is one inbound request, for assertions.
type Server ¶
type Server struct {
URL string
Origin string
Dir string
Name string
// contains filtered or unexported fields
}
Server is a local origin serving one fixture tree.
func ServeHook ¶
ServeHook starts fixture <name> after hook registers extra paths (key directory, for example). Register those before returning; the fixture catch-all is attached after hook.
func (*Server) Close ¶
func (s *Server) Close()
Close shuts the server down. Serve already registers Cleanup.
func (*Server) Requests ¶
func (s *Server) Requests() []RequestLog
Requests returns a copy of the inbound log.
type When ¶
type When struct {
UserAgentContains string `json:"user_agent_contains,omitempty"`
AcceptPrefers string `json:"accept_prefers,omitempty"`
HasSignature *bool `json:"has_signature,omitempty"`
Hit int `json:"hit,omitempty"`
}
When restricts a page to a class of request. All set fields must match. An empty When matches everything.