Home / Function/ Test_Logger_WithLatency_DefaultFormat() — fiber Function Reference

Test_Logger_WithLatency_DefaultFormat() — fiber Function Reference

Architecture documentation for the Test_Logger_WithLatency_DefaultFormat() function in logger_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  1b7d2c5a_64b9_f2f0_601a_11bc66b47b03["Test_Logger_WithLatency_DefaultFormat()"]
  97b45bc9_01a3_2a9a_4c94_9de1344ca94c["logger_test.go"]
  1b7d2c5a_64b9_f2f0_601a_11bc66b47b03 -->|defined in| 97b45bc9_01a3_2a9a_4c94_9de1344ca94c
  7a3c1ae2_ef11_b503_1eb9_203777026383["getLatencyTimeUnits()"]
  1b7d2c5a_64b9_f2f0_601a_11bc66b47b03 -->|calls| 7a3c1ae2_ef11_b503_1eb9_203777026383
  style 1b7d2c5a_64b9_f2f0_601a_11bc66b47b03 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/logger/logger_test.go lines 648–692

func Test_Logger_WithLatency_DefaultFormat(t *testing.T) {
	buff := bytebufferpool.Get()
	defer bytebufferpool.Put(buff)
	app := fiber.New()

	logger := New(Config{
		Stream: buff,
	})
	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:       2 * 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
		// parse out the latency value from the log output
		latency := bytes.Split(buff.Bytes(), []byte(" | "))[2]
		// Assert that the latency value is in the current time unit
		require.True(t, bytes.HasSuffix(latency, []byte(tu.unit)), "Expected latency to be in %s, got %s", tu.unit, latency)

		// Reset the buffer
		buff.Reset()
	}
}

Domain

Subdomains

Frequently Asked Questions

What does Test_Logger_WithLatency_DefaultFormat() do?
Test_Logger_WithLatency_DefaultFormat() is a function in the fiber codebase, defined in middleware/logger/logger_test.go.
Where is Test_Logger_WithLatency_DefaultFormat() defined?
Test_Logger_WithLatency_DefaultFormat() is defined in middleware/logger/logger_test.go at line 648.
What does Test_Logger_WithLatency_DefaultFormat() call?
Test_Logger_WithLatency_DefaultFormat() 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