Last active
April 5, 2016 14:48
-
-
Save jochasinga/16936e026027fdeec808b21403c9e7d8 to your computer and use it in GitHub Desktop.
Creating a standard test server in goconvey testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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