Home / Function/ Test_Cache_VaryAndAuth() — fiber Function Reference

Test_Cache_VaryAndAuth() — fiber Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  90f1635b_2386_a4b0_203a_6cde9263a618["Test_Cache_VaryAndAuth()"]
  8453a087_9678_fe96_1b20_2d125b6f8656["cache_test.go"]
  90f1635b_2386_a4b0_203a_6cde9263a618 -->|defined in| 8453a087_9678_fe96_1b20_2d125b6f8656
  764bea14_4c8a_81bd_ccd6_a1952b5d95d1["newFailingCacheStorage()"]
  90f1635b_2386_a4b0_203a_6cde9263a618 -->|calls| 764bea14_4c8a_81bd_ccd6_a1952b5d95d1
  style 90f1635b_2386_a4b0_203a_6cde9263a618 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/cache/cache_test.go lines 4155–4223

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

	t.Run("storeVaryManifest failure", func(t *testing.T) {
		t.Parallel()
		storage := newFailingCacheStorage()
		storage.errs["set|manifest"] = errors.New("storage fail")
		manager := &manager{storage: storage}
		err := storeVaryManifest(context.Background(), manager, "manifest", []string{"Accept"}, 3600*time.Second)
		require.Error(t, err)
	})

	t.Run("loadVaryManifest not found", func(t *testing.T) {
		t.Parallel()
		storage := newFailingCacheStorage()
		manager := &manager{storage: storage}
		varyNames, found, err := loadVaryManifest(context.Background(), manager, "nonexistent")
		require.NoError(t, err)
		require.False(t, found)
		require.Nil(t, varyNames)
	})

	t.Run("vary with multiple headers", func(t *testing.T) {
		t.Parallel()
		app := fiber.New()
		app.Use(New(Config{Expiration: 1 * time.Hour}))
		app.Get("/test", func(c fiber.Ctx) error {
			c.Response().Header.Set("Vary", "Accept, Accept-Encoding")
			c.Response().Header.Set("Cache-Control", "max-age=3600")
			return c.SendString("test")
		})

		req := httptest.NewRequest(fiber.MethodGet, "/test", http.NoBody)
		req.Header.Set("Accept", "application/json")
		req.Header.Set("Accept-Encoding", "gzip")
		rsp, err := app.Test(req)
		require.NoError(t, err)
		require.Equal(t, cacheMiss, rsp.Header.Get("X-Cache"))

		req2 := httptest.NewRequest(fiber.MethodGet, "/test", http.NoBody)
		req2.Header.Set("Accept", "application/json")
		req2.Header.Set("Accept-Encoding", "gzip")
		rsp2, err := app.Test(req2)
		require.NoError(t, err)
		require.Equal(t, cacheHit, rsp2.Header.Get("X-Cache"))
	})

	t.Run("auth with must-revalidate", func(t *testing.T) {
		t.Parallel()
		app := fiber.New()
		app.Use(New(Config{Expiration: 1 * time.Hour}))
		app.Get("/test", func(c fiber.Ctx) error {
			c.Response().Header.Set("Cache-Control", "must-revalidate, max-age=3600")
			return c.SendString("content")
		})

		req := httptest.NewRequest(fiber.MethodGet, "/test", http.NoBody)
		req.Header.Set("Authorization", "Bearer token1")
		rsp, err := app.Test(req)
		require.NoError(t, err)
		require.Equal(t, cacheMiss, rsp.Header.Get("X-Cache"))

		req2 := httptest.NewRequest(fiber.MethodGet, "/test", http.NoBody)
		req2.Header.Set("Authorization", "Bearer token1")
		rsp2, err := app.Test(req2)
		require.NoError(t, err)
		require.Equal(t, cacheHit, rsp2.Header.Get("X-Cache"))
	})
}

Subdomains

Frequently Asked Questions

What does Test_Cache_VaryAndAuth() do?
Test_Cache_VaryAndAuth() is a function in the fiber codebase, defined in middleware/cache/cache_test.go.
Where is Test_Cache_VaryAndAuth() defined?
Test_Cache_VaryAndAuth() is defined in middleware/cache/cache_test.go at line 4155.
What does Test_Cache_VaryAndAuth() call?
Test_Cache_VaryAndAuth() calls 1 function(s): newFailingCacheStorage.

Analyze Your Own Codebase

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

Try Supermodel Free