MCPcopy
hub / github.com/labstack/echo / TestRequestLogger_LogValuesFuncError

Function TestRequestLogger_LogValuesFuncError

middleware/request_logger_test.go:273–299  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

271}
272
273func TestRequestLogger_LogValuesFuncError(t *testing.T) {
274 e := echo.New()
275
276 var expect RequestLoggerValues
277 e.Use(RequestLoggerWithConfig(RequestLoggerConfig{
278 LogStatus: true,
279 LogValuesFunc: func(c *echo.Context, values RequestLoggerValues) error {
280 expect = values
281 return echo.NewHTTPError(http.StatusNotAcceptable, "LogValuesFuncError")
282 },
283 }))
284
285 e.GET("/test", func(c *echo.Context) error {
286 return c.String(http.StatusTeapot, "OK")
287 })
288
289 req := httptest.NewRequest(http.MethodGet, "/test", nil)
290 rec := httptest.NewRecorder()
291
292 e.ServeHTTP(rec, req)
293
294 // NOTE: when global error handler received error returned from middleware the status has already
295 // been written to the client and response has been "committed" therefore global error handler does not do anything
296 // and error that bubbled up in middleware chain will not be reflected in response code.
297 assert.Equal(t, http.StatusTeapot, rec.Code)
298 assert.Equal(t, http.StatusTeapot, expect.Status)
299}
300
301func TestRequestLogger_ID(t *testing.T) {
302 var testCases = []struct {

Callers

nothing calls this directly

Calls 5

RequestLoggerWithConfigFunction · 0.85
ServeHTTPMethod · 0.80
UseMethod · 0.45
GETMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…