Skip to content

Instantly share code, notes, and snippets.

@nidhi-canopas
Last active July 19, 2022 09:02
Show Gist options
  • Select an option

  • Save nidhi-canopas/342e6f26b8fa351d4b7f3bdb31d7eaf5 to your computer and use it in GitHub Desktop.

Select an option

Save nidhi-canopas/342e6f26b8fa351d4b7f3bdb31d7eaf5 to your computer and use it in GitHub Desktop.
// mock gin context
func GetTestGinContext() *gin.Context {
gin.SetMode(gin.TestMode)
w := httptest.NewRecorder()
ctx, _ := gin.CreateTestContext(w)
ctx.Request = &http.Request{
Header: make(http.Header),
URL: &url.URL{},
}
return ctx
}
// mock GET request
func MockJsonGet(c *gin.Context) {
c.Request.Method = "GET"
c.Request.Header.Set("Content-Type", "application/json")
c.Set("user_id", 1)
// set query params
u := url.Values{}
u.Add("skip", "5")
u.Add("limit", "10")
c.Request.URL.RawQuery = u.Encode()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment