Test_Cache_RequestResponseDirectives() — fiber Function Reference
Architecture documentation for the Test_Cache_RequestResponseDirectives() function in cache_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD e60dee51_dbec_1dc5_78e1_1cd50e1d0809["Test_Cache_RequestResponseDirectives()"] 8453a087_9678_fe96_1b20_2d125b6f8656["cache_test.go"] e60dee51_dbec_1dc5_78e1_1cd50e1d0809 -->|defined in| 8453a087_9678_fe96_1b20_2d125b6f8656 764bea14_4c8a_81bd_ccd6_a1952b5d95d1["newFailingCacheStorage()"] e60dee51_dbec_1dc5_78e1_1cd50e1d0809 -->|calls| 764bea14_4c8a_81bd_ccd6_a1952b5d95d1 style e60dee51_dbec_1dc5_78e1_1cd50e1d0809 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
middleware/cache/cache_test.go lines 4531–4838
func Test_Cache_RequestResponseDirectives(t *testing.T) {
t.Parallel()
t.Run("negative expiration skips caching", func(t *testing.T) {
t.Parallel()
app := fiber.New()
app.Use(New(Config{Expiration: -1 * time.Second}))
app.Get("/test", func(c fiber.Ctx) error {
return c.SendString("test")
})
rsp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", http.NoBody))
require.NoError(t, err)
require.NotEqual(t, cacheMiss, rsp.Header.Get("X-Cache"))
require.NotEqual(t, cacheHit, rsp.Header.Get("X-Cache"))
})
t.Run("request with no-store directive", 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 {
return c.SendString("test")
})
req := httptest.NewRequest(fiber.MethodGet, "/test", http.NoBody)
req.Header.Set("Cache-Control", "no-store")
rsp, err := app.Test(req)
require.NoError(t, err)
require.NotEqual(t, cacheMiss, rsp.Header.Get("X-Cache"))
})
t.Run("request with pragma no-cache", 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", "max-age=3600")
return c.SendString("test")
})
req := httptest.NewRequest(fiber.MethodGet, "/test", http.NoBody)
req.Header.Set("Pragma", "no-cache")
rsp, err := app.Test(req)
require.NoError(t, err)
require.Equal(t, cacheMiss, rsp.Header.Get("X-Cache"))
})
t.Run("method not in allowed methods list", func(t *testing.T) {
t.Parallel()
app := fiber.New()
app.Use(New(Config{
Expiration: 1 * time.Hour,
Methods: []string{fiber.MethodGet},
}))
app.Post("/test", func(c fiber.Ctx) error {
return c.SendString("test")
})
rsp, err := app.Test(httptest.NewRequest(fiber.MethodPost, "/test", http.NoBody))
require.NoError(t, err)
require.Equal(t, cacheUnreachable, rsp.Header.Get("X-Cache"))
})
t.Run("request with min-fresh directive", 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", "max-age=60")
return c.SendString("test")
})
// First request to cache
rsp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", http.NoBody))
require.NoError(t, err)
require.Equal(t, cacheMiss, rsp.Header.Get("X-Cache"))
// Second request with min-fresh that's too high
req := httptest.NewRequest(fiber.MethodGet, "/test", http.NoBody)
req.Header.Set("Cache-Control", "min-fresh=120")
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does Test_Cache_RequestResponseDirectives() do?
Test_Cache_RequestResponseDirectives() is a function in the fiber codebase, defined in middleware/cache/cache_test.go.
Where is Test_Cache_RequestResponseDirectives() defined?
Test_Cache_RequestResponseDirectives() is defined in middleware/cache/cache_test.go at line 4531.
What does Test_Cache_RequestResponseDirectives() call?
Test_Cache_RequestResponseDirectives() 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