MCPcopy
hub / github.com/gin-gonic/gin / TestLoggerWithConfigSkipper

Function TestLoggerWithConfigSkipper

logger_test.go:436–454  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

434}
435
436func TestLoggerWithConfigSkipper(t *testing.T) {
437 buffer := new(strings.Builder)
438 router := New()
439 router.Use(LoggerWithConfig(LoggerConfig{
440 Output: buffer,
441 Skip: func(c *Context) bool {
442 return c.Writer.Status() == http.StatusNoContent
443 },
444 }))
445 router.GET("/logged", func(c *Context) { c.Status(http.StatusOK) })
446 router.GET("/skipped", func(c *Context) { c.Status(http.StatusNoContent) })
447
448 PerformRequest(router, http.MethodGet, "/logged")
449 assert.Contains(t, buffer.String(), "200")
450
451 buffer.Reset()
452 PerformRequest(router, http.MethodGet, "/skipped")
453 assert.Contains(t, buffer.String(), "")
454}
455
456func TestDisableConsoleColor(t *testing.T) {
457 New()

Callers

nothing calls this directly

Calls 8

NewFunction · 0.85
LoggerWithConfigFunction · 0.85
PerformRequestFunction · 0.85
UseMethod · 0.65
StatusMethod · 0.65
GETMethod · 0.65
StringMethod · 0.65
ResetMethod · 0.45

Tested by

no test coverage detected