Home / Function/ Test_CacheNoCacheDirectiveOverridesExistingEntry() — fiber Function Reference

Test_CacheNoCacheDirectiveOverridesExistingEntry() — fiber Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

middleware/cache/cache_test.go lines 2636–2676

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

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

	var noCacheMode atomic.Bool
	app.Get("/", func(c fiber.Ctx) error {
		if noCacheMode.Load() {
			c.Set(fiber.HeaderCacheControl, "no-cache")
			return c.SendString("no-cache")
		}

		c.Set(fiber.HeaderCacheControl, "public, max-age=60")
		return c.SendString("cacheable")
	})

	resp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/", http.NoBody))
	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, "cacheable", string(body))

	noCacheMode.Store(true)
	req := httptest.NewRequest(fiber.MethodGet, "/", http.NoBody)
	req.Header.Set(fiber.HeaderCacheControl, "no-cache")
	resp, err = app.Test(req)
	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, "no-cache", string(body))

	resp, err = app.Test(httptest.NewRequest(fiber.MethodGet, "/", http.NoBody))
	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, "no-cache", string(body))
}

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free