(req any, method, url string, handlerFunc gin.HandlerFunc)
| 135 | } |
| 136 | |
| 137 | func requestAPI(req any, method, url string, handlerFunc gin.HandlerFunc) error { |
| 138 | w := httptest.NewRecorder() |
| 139 | c, _ := gin.CreateTestContext(w) |
| 140 | body, _ := json.Marshal(req) |
| 141 | c.Request, _ = http.NewRequest(method, url, bytes.NewBuffer(body)) |
| 142 | if method == "POST" { |
| 143 | c.Request.Header.Set("Content-Type", "application/json") |
| 144 | } |
| 145 | handlerFunc(c) |
| 146 | if w.Code != http.StatusOK { |
| 147 | return errors.New(gjson.Get(w.Body.String(), "msg").String()) |
| 148 | } |
| 149 | return nil |
| 150 | } |
no test coverage detected