Test_Logger_WithLatency() — fiber Function Reference
Architecture documentation for the Test_Logger_WithLatency() function in logger_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD 19bce48b_5ef4_c12e_24da_339eaf163633["Test_Logger_WithLatency()"] 97b45bc9_01a3_2a9a_4c94_9de1344ca94c["logger_test.go"] 19bce48b_5ef4_c12e_24da_339eaf163633 -->|defined in| 97b45bc9_01a3_2a9a_4c94_9de1344ca94c 7a3c1ae2_ef11_b503_1eb9_203777026383["getLatencyTimeUnits()"] 19bce48b_5ef4_c12e_24da_339eaf163633 -->|calls| 7a3c1ae2_ef11_b503_1eb9_203777026383 style 19bce48b_5ef4_c12e_24da_339eaf163633 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
middleware/logger/logger_test.go lines 603–645
func Test_Logger_WithLatency(t *testing.T) {
buff := bytebufferpool.Get()
defer bytebufferpool.Put(buff)
app := fiber.New()
logger := New(Config{
Stream: buff,
Format: "${latency}",
})
app.Use(logger)
// Define a list of time units to test
timeUnits := getLatencyTimeUnits()
// Initialize a new time unit
sleepDuration := 1 * time.Nanosecond
// Define a test route that sleeps
app.Get("/test", func(c fiber.Ctx) error {
time.Sleep(sleepDuration)
return c.SendStatus(fiber.StatusOK)
})
// Loop through each time unit and assert that the log output contains the expected latency value
for _, tu := range timeUnits {
// Update the sleep duration for the next iteration
sleepDuration = 1 * tu.div
// Create a new HTTP request to the test route
resp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", http.NoBody), fiber.TestConfig{
Timeout: 3 * time.Second,
FailOnTimeout: true,
})
require.NoError(t, err)
require.Equal(t, fiber.StatusOK, resp.StatusCode)
// Assert that the log output contains the expected latency value in the current time unit
require.True(t, bytes.HasSuffix(buff.Bytes(), []byte(tu.unit)), "Expected latency to be in %s, got %s", tu.unit, buff.String())
// Reset the buffer
buff.Reset()
}
}
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does Test_Logger_WithLatency() do?
Test_Logger_WithLatency() is a function in the fiber codebase, defined in middleware/logger/logger_test.go.
Where is Test_Logger_WithLatency() defined?
Test_Logger_WithLatency() is defined in middleware/logger/logger_test.go at line 603.
What does Test_Logger_WithLatency() call?
Test_Logger_WithLatency() calls 1 function(s): getLatencyTimeUnits.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free