Test_CacheVarySeparatesVariants() — fiber Function Reference
Architecture documentation for the Test_CacheVarySeparatesVariants() function in cache_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD 46f171eb_ffd5_95d9_a87e_7dc2c6aacbdc["Test_CacheVarySeparatesVariants()"] 8453a087_9678_fe96_1b20_2d125b6f8656["cache_test.go"] 46f171eb_ffd5_95d9_a87e_7dc2c6aacbdc -->|defined in| 8453a087_9678_fe96_1b20_2d125b6f8656 style 46f171eb_ffd5_95d9_a87e_7dc2c6aacbdc fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
middleware/cache/cache_test.go lines 2758–2810
func Test_CacheVarySeparatesVariants(t *testing.T) {
t.Parallel()
app := fiber.New()
app.Use(New(Config{
KeyGenerator: func(c fiber.Ctx) string {
return c.Path() + "|vary-separated"
},
}))
var count int
app.Get("/", func(c fiber.Ctx) error {
count++
c.Set(fiber.HeaderVary, fiber.HeaderAcceptLanguage)
return c.SendString(c.Get(fiber.HeaderAcceptLanguage) + strconv.Itoa(count))
})
reqEN := httptest.NewRequest(fiber.MethodGet, "/", http.NoBody)
reqEN.Header.Set(fiber.HeaderAcceptLanguage, "en")
resp, err := app.Test(reqEN)
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, "en1", string(body))
reqFR := httptest.NewRequest(fiber.MethodGet, "/", http.NoBody)
reqFR.Header.Set(fiber.HeaderAcceptLanguage, "fr")
resp, err = app.Test(reqFR)
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, "fr2", string(body))
reqENRepeat := httptest.NewRequest(fiber.MethodGet, "/", http.NoBody)
reqENRepeat.Header.Set(fiber.HeaderAcceptLanguage, "en")
resp, err = app.Test(reqENRepeat)
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, "en1", string(body))
reqFRRepeat := httptest.NewRequest(fiber.MethodGet, "/", http.NoBody)
reqFRRepeat.Header.Set(fiber.HeaderAcceptLanguage, "fr")
resp, err = app.Test(reqFRRepeat)
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, "fr2", string(body))
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does Test_CacheVarySeparatesVariants() do?
Test_CacheVarySeparatesVariants() is a function in the fiber codebase, defined in middleware/cache/cache_test.go.
Where is Test_CacheVarySeparatesVariants() defined?
Test_CacheVarySeparatesVariants() is defined in middleware/cache/cache_test.go at line 2758.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free