Documentation ¶
Index ¶
- func ContentHTML() http.HandlerFunc
- func ContentJSON() http.HandlerFunc
- func ContentMIME(mediaType string) http.HandlerFunc
- func ContentXML() http.HandlerFunc
- func Dummy() *httptest.Server
- func NewServer(handler http.HandlerFunc) *httptest.Server
- func Response(status int, data ...[]byte) http.HandlerFunc
- func ResponseString(status int, data string) http.HandlerFunc
- type Case
- type Conditional
- type Fixed
- type Switch
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContentHTML ¶
func ContentHTML() http.HandlerFunc
ContentHTML is a setup handler, which configures server to use HTML.
func ContentJSON ¶
func ContentJSON() http.HandlerFunc
ContentJSON is a setup handler, which configures server to use JSON.
func ContentMIME ¶
func ContentMIME(mediaType string) http.HandlerFunc
ContentMIME is a setup handler, which configures custom media type.
func ContentXML ¶
func ContentXML() http.HandlerFunc
ContentXML is a setup handler, which configures server to use XML.
func Dummy ¶
Dummy server only talks about having a cup of tea. Acknowledges requests and does nothing else.
func NewServer ¶
func NewServer(handler http.HandlerFunc) *httptest.Server
NewServer is syntactic sugar for creating test server.
func Response ¶
func Response(status int, data ...[]byte) http.HandlerFunc
Response is used to configure server response with HTTP status and body data. Data is optional.
func ResponseString ¶
func ResponseString(status int, data string) http.HandlerFunc
Types ¶
type Case ¶
type Case struct { // If, may consist of nested Or, And clauses allowing sophisticated logic. If mockcond.Condition // Then will be called when If evaluates to true. Then http.HandlerFunc }
Case is one possible route a mock server can take if condition is satisfied.
type Conditional ¶
type Conditional struct { // Setup is optional handler, where common http.ResponseWrite configuration takes place. Setup http.HandlerFunc // If, may consist of nested Or, And clauses allowing sophisticated logic. If mockcond.Condition // Then will be called when If evaluates to true. Then http.HandlerFunc // Else will be called when If evaluates to false. Else http.HandlerFunc }
Conditional is a server recipe that describes how mock server should react when conditions are met. It is equivalent to If() Then{} Else{}.
func (Conditional) Server ¶
func (re Conditional) Server() *httptest.Server
Server creates mock server that will produce different response based on conditionals.
type Fixed ¶
type Fixed struct { // Setup is optional handler, where common http.ResponseWrite configuration takes place. Setup http.HandlerFunc // Always represents server handler that should implement how server should respond. Always http.HandlerFunc }
Fixed is a server recipe that responds the same way regardless of the input.
type Switch ¶
type Switch struct { // Setup is optional handler, where common http.ResponseWrite configuration takes place. Setup http.HandlerFunc // Cases is an ordered list of possible pathways a mock server could take. // The first case that satisfies a condition will be picked. Cases []Case // Default will be called only if all case had failed. Default http.HandlerFunc }
Switch is a server recipe that describes multiple path a server may take. It is equivalent to Switch() {Case->Then...Case->Then} Default{}.