Reputation: 43
I'm very new to Go and was wondering is there any convention/standard with examples on how to test Go Martini's Handler code?
Thanking you in advance!
Upvotes: 1
Views: 408
Reputation: 24260
The martini-contrib library has a lot of existing code worth looking at: https://github.com/martini-contrib/secure/blob/master/secure_test.go
e.g.
func Test_No_Config(t *testing.T) {
m := martini.Classic()
m.Use(Secure(Options{
// nothing here to configure
}))
m.Get("/foo", func() string {
return "bar"
})
res := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/foo", nil)
m.ServeHTTP(res, req)
expect(t, res.Code, http.StatusOK)
expect(t, res.Body.String(), `bar`)
}
To sum:
martini.Classic()
Upvotes: 3