Home / Function/ TestCacheBypassesExistingEntryForAuthorization() — fiber Function Reference

TestCacheBypassesExistingEntryForAuthorization() — fiber Function Reference

Architecture documentation for the TestCacheBypassesExistingEntryForAuthorization() function in cache_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  f818e97c_6035_24d0_f61c_3dce7c09f72b["TestCacheBypassesExistingEntryForAuthorization()"]
  8453a087_9678_fe96_1b20_2d125b6f8656["cache_test.go"]
  f818e97c_6035_24d0_f61c_3dce7c09f72b -->|defined in| 8453a087_9678_fe96_1b20_2d125b6f8656
  style f818e97c_6035_24d0_f61c_3dce7c09f72b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/cache/cache_test.go lines 3082–3119

func TestCacheBypassesExistingEntryForAuthorization(t *testing.T) {
	t.Parallel()

	app := fiber.New()
	app.Use(New())

	var count int
	app.Get("/", func(c fiber.Ctx) error {
		count++
		return c.SendString(strconv.Itoa(count))
	})

	nonAuthReq := httptest.NewRequest(fiber.MethodGet, "/", http.NoBody)

	resp, err := app.Test(nonAuthReq)
	require.NoError(t, err)
	require.Equal(t, cacheMiss, resp.Header.Get("X-Cache"))
	body, err := io.ReadAll(resp.Body)
	require.NoError(t, err)
	require.Equal(t, "1", string(body))

	authReq := httptest.NewRequest(fiber.MethodGet, "/", http.NoBody)
	authReq.Header.Set(fiber.HeaderAuthorization, "Bearer token")

	resp, err = app.Test(authReq)
	require.NoError(t, err)
	require.Equal(t, cacheUnreachable, resp.Header.Get("X-Cache"))
	body, err = io.ReadAll(resp.Body)
	require.NoError(t, err)
	require.Equal(t, "2", string(body))

	resp, err = app.Test(nonAuthReq)
	require.NoError(t, err)
	require.Equal(t, cacheHit, resp.Header.Get("X-Cache"))
	body, err = io.ReadAll(resp.Body)
	require.NoError(t, err)
	require.Equal(t, "1", string(body))
}

Subdomains

Frequently Asked Questions

What does TestCacheBypassesExistingEntryForAuthorization() do?
TestCacheBypassesExistingEntryForAuthorization() is a function in the fiber codebase, defined in middleware/cache/cache_test.go.
Where is TestCacheBypassesExistingEntryForAuthorization() defined?
TestCacheBypassesExistingEntryForAuthorization() is defined in middleware/cache/cache_test.go at line 3082.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free