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

Function TestRequestLogger_ID

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

Source from the content-addressed store, hash-verified

299}
300
301func TestRequestLogger_ID(t *testing.T) {
302 var testCases = []struct {
303 name string
304 whenFromRequest bool
305 expect string
306 }{
307 {
308 name: "ok, ID is provided from request headers",
309 whenFromRequest: true,
310 expect: "123",
311 },
312 {
313 name: "ok, ID is from response headers",
314 whenFromRequest: false,
315 expect: "321",
316 },
317 }
318
319 for _, tc := range testCases {
320 t.Run(tc.name, func(t *testing.T) {
321 e := echo.New()
322
323 var expect RequestLoggerValues
324 e.Use(RequestLoggerWithConfig(RequestLoggerConfig{
325 LogRequestID: true,
326 LogValuesFunc: func(c *echo.Context, values RequestLoggerValues) error {
327 expect = values
328 return nil
329 },
330 }))
331
332 e.GET("/test", func(c *echo.Context) error {
333 c.Response().Header().Set(echo.HeaderXRequestID, "321")
334 return c.String(http.StatusTeapot, "OK")
335 })
336
337 req := httptest.NewRequest(http.MethodGet, "/test", nil)
338 if tc.whenFromRequest {
339 req.Header.Set(echo.HeaderXRequestID, "123")
340 }
341 rec := httptest.NewRecorder()
342
343 e.ServeHTTP(rec, req)
344
345 assert.Equal(t, http.StatusTeapot, rec.Code)
346 assert.Equal(t, tc.expect, expect.RequestID)
347 })
348 }
349}
350
351func TestRequestLogger_headerIsCaseInsensitive(t *testing.T) {
352 e := echo.New()

Callers

nothing calls this directly

Calls 8

RequestLoggerWithConfigFunction · 0.85
SetMethod · 0.80
ResponseMethod · 0.80
ServeHTTPMethod · 0.80
UseMethod · 0.45
GETMethod · 0.45
HeaderMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…