TestCacheAllowsAuthorizationWithRevalidateDirectives() — fiber Function Reference
Architecture documentation for the TestCacheAllowsAuthorizationWithRevalidateDirectives() function in cache_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD 93a9e1b8_57b3_dc1e_ef6c_a59bb696677f["TestCacheAllowsAuthorizationWithRevalidateDirectives()"] 8453a087_9678_fe96_1b20_2d125b6f8656["cache_test.go"] 93a9e1b8_57b3_dc1e_ef6c_a59bb696677f -->|defined in| 8453a087_9678_fe96_1b20_2d125b6f8656 style 93a9e1b8_57b3_dc1e_ef6c_a59bb696677f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
middleware/cache/cache_test.go lines 3153–3233
func TestCacheAllowsAuthorizationWithRevalidateDirectives(t *testing.T) {
t.Parallel()
tests := []struct {
name string
cacheControl string
expires string
expectedBody string
expectedBody2 string
expectFirst string
expectSecond string
}{
{
name: "must-revalidate",
cacheControl: "must-revalidate, max-age=60",
expectedBody: "ok-1",
expectedBody2: "ok-1",
expectFirst: cacheMiss,
expectSecond: cacheHit,
},
{
name: "proxy-revalidate",
cacheControl: "proxy-revalidate, max-age=60",
expectedBody: "ok-1",
expectedBody2: "ok-1",
expectFirst: cacheMiss,
expectSecond: cacheHit,
},
{
name: "expires header",
cacheControl: "",
expires: time.Now().Add(1 * time.Minute).UTC().Format(http.TimeFormat),
expectedBody: "ok-1",
expectedBody2: "ok-2",
expectFirst: cacheUnreachable,
expectSecond: cacheUnreachable,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
app := fiber.New()
app.Use(New(Config{Expiration: 10 * time.Second}))
var count int
app.Get("/", func(c fiber.Ctx) error {
count++
c.Set(fiber.HeaderCacheControl, tt.cacheControl)
if tt.expires != "" {
c.Set(fiber.HeaderExpires, tt.expires)
}
return c.SendString(fmt.Sprintf("ok-%d", count))
})
req := httptest.NewRequest(fiber.MethodGet, "/", http.NoBody)
req.Header.Set(fiber.HeaderAuthorization, "Bearer token")
resp, err := app.Test(req)
require.NoError(t, err)
require.Equal(t, tt.expectFirst, resp.Header.Get("X-Cache"))
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.Equal(t, tt.expectedBody, string(body))
resp, err = app.Test(req)
require.NoError(t, err)
require.Equal(t, tt.expectSecond, resp.Header.Get("X-Cache"))
body, err = io.ReadAll(resp.Body)
require.NoError(t, err)
require.Equal(t, tt.expectedBody2, string(body))
if tt.expectSecond == cacheHit {
require.Equal(t, 1, count)
} else {
require.Equal(t, 2, count)
}
})
}
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does TestCacheAllowsAuthorizationWithRevalidateDirectives() do?
TestCacheAllowsAuthorizationWithRevalidateDirectives() is a function in the fiber codebase, defined in middleware/cache/cache_test.go.
Where is TestCacheAllowsAuthorizationWithRevalidateDirectives() defined?
TestCacheAllowsAuthorizationWithRevalidateDirectives() is defined in middleware/cache/cache_test.go at line 3153.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free