MCPcopy
hub / github.com/gofiber/fiber / Test_Logger_New_TimeDoneUpdater

Function Test_Logger_New_TimeDoneUpdater

middleware/logger/coverage_test.go:174–204  ·  view source on GitHub ↗

Test_Logger_New_TimeDoneUpdater verifies the New path that starts a dedicated timestamp updater when TimeDone is configured (covers startTimestampUpdater).

(t *testing.T)

Source from the content-addressed store, hash-verified

172// Test_Logger_New_TimeDoneUpdater verifies the New path that starts a dedicated
173// timestamp updater when TimeDone is configured (covers startTimestampUpdater).
174func Test_Logger_New_TimeDoneUpdater(t *testing.T) {
175 t.Parallel()
176
177 done := make(chan struct{})
178 defer close(done)
179
180 buf := bytes.NewBuffer(nil)
181 app := fiber.New()
182 app.Use(New(Config{
183 Format: "${time}\n",
184 TimeFormat: time.RFC3339Nano,
185 TimeInterval: 5 * time.Millisecond,
186 TimeDone: done,
187 Stream: buf,
188 }))
189 app.Get("/", func(c fiber.Ctx) error {
190 return c.SendString("ok")
191 })
192
193 resp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/", http.NoBody))
194 require.NoError(t, err)
195 require.Equal(t, fiber.StatusOK, resp.StatusCode)
196
197 // The format always emits a trailing newline, so a non-empty buffer alone
198 // would pass even if ${time} rendered empty. Trim it and assert the rendered
199 // timestamp is present and well-formed, proving the updater path ran.
200 rendered := strings.TrimRight(buf.String(), "\n")
201 require.NotEmpty(t, rendered)
202 _, parseErr := time.Parse(time.RFC3339Nano, rendered)
203 require.NoError(t, parseErr)
204}

Callers

nothing calls this directly

Calls 8

StringMethod · 0.95
TestMethod · 0.80
NewFunction · 0.70
NewMethod · 0.65
UseMethod · 0.65
GetMethod · 0.65
SendStringMethod · 0.65
ParseMethod · 0.65

Tested by

no test coverage detected