Skip to content

Instantly share code, notes, and snippets.

@tonespy
Created June 23, 2019 12:42
Show Gist options
  • Save tonespy/eb34244e51decbd87f1a14d810a43b42 to your computer and use it in GitHub Desktop.
Save tonespy/eb34244e51decbd87f1a14d810a43b42 to your computer and use it in GitHub Desktop.
API Mock
// mockRequestHandler :- Mocks a handler and returns a httptest.ResponseRecorder
func mockRequestHandler(req *http.Request, method string, path string, reqHandler func(w http.ResponseWriter, r *http.Request, param httprouter.Params)) *httptest.ResponseRecorder {
router := httprouter.New()
router.Handle(method, path, reqHandler)
recorder := httptest.NewRecorder()
router.ServeHTTP(recorder, req)
return recorder
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment