TestCacheStorageOperationsObserveRequestContext() — fiber Function Reference
Architecture documentation for the TestCacheStorageOperationsObserveRequestContext() function in cache_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD fd2bca04_19f0_1e38_9da6_7edbe8446cf4["TestCacheStorageOperationsObserveRequestContext()"] 8453a087_9678_fe96_1b20_2d125b6f8656["cache_test.go"] fd2bca04_19f0_1e38_9da6_7edbe8446cf4 -->|defined in| 8453a087_9678_fe96_1b20_2d125b6f8656 dd1b3634_0cbf_5a63_3fcc_869cfe1a2add["newContextRecorderStorage()"] fd2bca04_19f0_1e38_9da6_7edbe8446cf4 -->|calls| dd1b3634_0cbf_5a63_3fcc_869cfe1a2add 7de6ac74_535e_b3de_5e3a_aab85ae3edca["canceledContextWithMarker()"] fd2bca04_19f0_1e38_9da6_7edbe8446cf4 -->|calls| 7de6ac74_535e_b3de_5e3a_aab85ae3edca 2018faac_33e1_3614_02e8_25e358c08098["contextWithMarker()"] fd2bca04_19f0_1e38_9da6_7edbe8446cf4 -->|calls| 2018faac_33e1_3614_02e8_25e358c08098 style fd2bca04_19f0_1e38_9da6_7edbe8446cf4 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
middleware/cache/cache_test.go lines 411–483
func TestCacheStorageOperationsObserveRequestContext(t *testing.T) {
t.Parallel()
storage := newContextRecorderStorage()
app := fiber.New()
app.Use(func(c fiber.Ctx) error {
ctxLabel := string(c.Request().Header.Peek("X-Context"))
if ctxLabel == "" {
return c.Next()
}
canceled := string(c.Request().Header.Peek("X-Cancel")) == "true"
if canceled {
c.SetContext(canceledContextWithMarker(ctxLabel))
} else {
c.SetContext(contextWithMarker(ctxLabel))
}
return c.Next()
})
app.Use(New(Config{Storage: storage, Expiration: time.Minute}))
app.Get("/cache", func(c fiber.Ctx) error {
return c.SendString("payload")
})
firstReq := httptest.NewRequest(fiber.MethodGet, "/cache", http.NoBody)
firstReq.Header.Set("X-Context", "store")
firstReq.Header.Set("X-Cancel", "true")
resp, err := app.Test(firstReq)
require.NoError(t, err)
require.Equal(t, fiber.StatusOK, resp.StatusCode)
secondReq := httptest.NewRequest(fiber.MethodGet, "/cache", http.NoBody)
secondReq.Header.Set("X-Context", "fetch")
secondReq.Header.Set("X-Cancel", "true")
resp, err = app.Test(secondReq)
require.NoError(t, err)
require.Equal(t, fiber.StatusOK, resp.StatusCode)
setRecords := storage.recordedSets()
require.Len(t, setRecords, 2)
for _, rec := range setRecords {
require.Contains(t, []string{"/cache_GET", "/cache_GET_body"}, rec.key)
require.Equal(t, "store", rec.value)
require.True(t, rec.canceled)
}
getRecords := storage.recordedGets()
require.NotEmpty(t, getRecords)
var fetchEntry, fetchBody bool
for _, rec := range getRecords {
if rec.value != "fetch" {
continue
}
if rec.key == "/cache_GET" {
require.True(t, rec.canceled)
fetchEntry = true
}
if rec.key == "/cache_GET_body" {
require.True(t, rec.canceled)
fetchBody = true
}
}
require.True(t, fetchEntry, "expected cached entry retrieval to observe request context")
require.True(t, fetchBody, "expected cached body retrieval to observe request context")
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does TestCacheStorageOperationsObserveRequestContext() do?
TestCacheStorageOperationsObserveRequestContext() is a function in the fiber codebase, defined in middleware/cache/cache_test.go.
Where is TestCacheStorageOperationsObserveRequestContext() defined?
TestCacheStorageOperationsObserveRequestContext() is defined in middleware/cache/cache_test.go at line 411.
What does TestCacheStorageOperationsObserveRequestContext() call?
TestCacheStorageOperationsObserveRequestContext() calls 3 function(s): canceledContextWithMarker, contextWithMarker, newContextRecorderStorage.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free