Skip to content

Instantly share code, notes, and snippets.

@jochasinga
Last active April 5, 2016 14:48
Show Gist options
  • Save jochasinga/16936e026027fdeec808b21403c9e7d8 to your computer and use it in GitHub Desktop.
Save jochasinga/16936e026027fdeec808b21403c9e7d8 to your computer and use it in GitHub Desktop.
Creating a standard test server in goconvey testing
// Error handling omitted for brevity
var handler = func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello world!")
}
func TestGet(t *testing.T) {
Convey("GIVEN a test server", t, func() {
ts := httptest.NewServer(http.HandlerFunc(handler))
Convey("WITH a GET request", func() {
resp, _ := http.Get(ts.URL)
Convey("EXPECT `Hello world!` as a response", func() {
b, _ := ioutil.ReadAll(resp.Body)
So(string(b), ShouldEqual, "Hello world!")
})
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment