Unable to POST to gin
mdonnellyli opened this issue · 1 comments
mdonnellyli commented
I am using this method to try and test Gin POST and get the following error - any ideas?
./audit_handler_test.go:39: cannot use GetMainEngine (type func() *gin.Engine) as type http.Handler in argument to r.POST("/log").SetJSON(gofight.D literal).SetDebug(true).Run:
func() *gin.Engine does not implement http.Handler (missing ServeHTTP method)
FAIL placeable.com/audit-server [build failed]
`func GetMainEngine() *gin.Engine {
r := gin.Default()
v1 := r.Group("/v1")
{
v1.POST("/log", SendAuditHandler)
}
return r
}`
`
func TestPOSTData(t *testing.T) {
r := gofight.New()
r.POST("/log").SetJSON(gofight.D{
"a": 1,
"b": 2,
}).
SetDebug(true).
Run(GetMainEngine, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
assert.Equal(t, http.StatusBadRequest, r.Code)
})
}
`
mdonnellyli commented
I was missing () on the GetMainEngine method. Sorry.