Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
Hander defines the endpoint and response from your http test server
Example (Serve) ¶
testServer := Handler{Response: testhelpers.LoadFile(&testing.T{}, "testdata/identity.json")}.Serve() defer testServer.Close() resp, err := http.Get(testServer.URL) if err != nil { fmt.Println(err) } b, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err) } fmt.Println(string(b))
Output: { "id": "1a", "type": "hero" }
type Handlers ¶ added in v0.4.0
func NewHandlers ¶ added in v0.4.0
NewHandlers initializes a new set of handlers
type Server ¶
Server wraps a httptest server and will loop over its handlers to return a response from the test server
Example ¶
testServer := New(Handler{Status: http.StatusCreated, Response: []byte("success")}, Handler{Status: http.StatusRequestTimeout, Response: []byte("timeout")}) defer testServer.Close() resp, _ := http.Get(testServer.URL) b, _ := ioutil.ReadAll(resp.Body) fmt.Printf("%d: %s\n", resp.StatusCode, string(b)) resp.Body.Close() resp, _ = http.Get(testServer.URL) b, _ = ioutil.ReadAll(resp.Body) fmt.Printf("%d: %s\n", resp.StatusCode, string(b)) resp.Body.Close() resp, _ = http.Get(testServer.URL) b, _ = ioutil.ReadAll(resp.Body) fmt.Printf("%d: %s\n", resp.StatusCode, string(b)) resp.Body.Close()
Output: 201: success 408: timeout 201: success
Click to show internal directories.
Click to hide internal directories.