(t *testing.T)
| 374 | } |
| 375 | |
| 376 | func TestErrorLogger(t *testing.T) { |
| 377 | router := New() |
| 378 | router.Use(ErrorLogger()) |
| 379 | router.GET("/error", func(c *Context) { |
| 380 | c.Error(errors.New("this is an error")) //nolint: errcheck |
| 381 | }) |
| 382 | router.GET("/abort", func(c *Context) { |
| 383 | c.AbortWithError(http.StatusUnauthorized, errors.New("no authorized")) //nolint: errcheck |
| 384 | }) |
| 385 | router.GET("/print", func(c *Context) { |
| 386 | c.Error(errors.New("this is an error")) //nolint: errcheck |
| 387 | c.String(http.StatusInternalServerError, "hola!") |
| 388 | }) |
| 389 | |
| 390 | w := PerformRequest(router, http.MethodGet, "/error") |
| 391 | assert.Equal(t, http.StatusOK, w.Code) |
| 392 | assert.JSONEq(t, "{\"error\":\"this is an error\"}", w.Body.String()) |
| 393 | |
| 394 | w = PerformRequest(router, http.MethodGet, "/abort") |
| 395 | assert.Equal(t, http.StatusUnauthorized, w.Code) |
| 396 | assert.JSONEq(t, "{\"error\":\"no authorized\"}", w.Body.String()) |
| 397 | |
| 398 | w = PerformRequest(router, http.MethodGet, "/print") |
| 399 | assert.Equal(t, http.StatusInternalServerError, w.Code) |
| 400 | assert.Equal(t, "hola!{\"error\":\"this is an error\"}", w.Body.String()) |
| 401 | } |
| 402 | |
| 403 | func TestLoggerWithWriterSkippingPaths(t *testing.T) { |
| 404 | buffer := new(strings.Builder) |
nothing calls this directly
no test coverage detected