Last active
July 19, 2022 09:02
-
-
Save nidhi-canopas/342e6f26b8fa351d4b7f3bdb31d7eaf5 to your computer and use it in GitHub Desktop.
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
| // 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