Home / Function/ TestCacheEvictionPropagatesRequestContextToDelete() — fiber Function Reference

TestCacheEvictionPropagatesRequestContextToDelete() — fiber Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  91805460_0832_eea8_078a_68361793a0d5["TestCacheEvictionPropagatesRequestContextToDelete()"]
  8453a087_9678_fe96_1b20_2d125b6f8656["cache_test.go"]
  91805460_0832_eea8_078a_68361793a0d5 -->|defined in| 8453a087_9678_fe96_1b20_2d125b6f8656
  dd1b3634_0cbf_5a63_3fcc_869cfe1a2add["newContextRecorderStorage()"]
  91805460_0832_eea8_078a_68361793a0d5 -->|calls| dd1b3634_0cbf_5a63_3fcc_869cfe1a2add
  2018faac_33e1_3614_02e8_25e358c08098["contextWithMarker()"]
  91805460_0832_eea8_078a_68361793a0d5 -->|calls| 2018faac_33e1_3614_02e8_25e358c08098
  7de6ac74_535e_b3de_5e3a_aab85ae3edca["canceledContextWithMarker()"]
  91805460_0832_eea8_078a_68361793a0d5 -->|calls| 7de6ac74_535e_b3de_5e3a_aab85ae3edca
  style 91805460_0832_eea8_078a_68361793a0d5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/cache/cache_test.go lines 325–371

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

	storage := newContextRecorderStorage()
	app := fiber.New()

	app.Use(func(c fiber.Ctx) error {
		path := c.Path()
		if path == "/first" {
			c.SetContext(contextWithMarker("first"))
		}
		if path == "/second" {
			c.SetContext(canceledContextWithMarker("evict"))
		}
		return c.Next()
	})

	app.Use(New(Config{Storage: storage, Expiration: time.Minute, MaxBytes: 5}))

	app.Get("/first", func(c fiber.Ctx) error {
		return c.SendString("aaa")
	})

	app.Get("/second", func(c fiber.Ctx) error {
		return c.SendString("bbbb")
	})

	resp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/first", http.NoBody))
	require.NoError(t, err)
	require.Equal(t, fiber.StatusOK, resp.StatusCode)

	resp, err = app.Test(httptest.NewRequest(fiber.MethodGet, "/second", http.NoBody))
	require.NoError(t, err)
	require.Equal(t, fiber.StatusOK, resp.StatusCode)

	records := storage.recordedDeletes()
	require.Len(t, records, 2)

	var keys []string
	for _, rec := range records {
		keys = append(keys, rec.key)
		require.Equal(t, "evict", rec.value)
		require.True(t, rec.canceled)
	}

	require.ElementsMatch(t, []string{"/first_GET", "/first_GET_body"}, keys)
}

Subdomains

Frequently Asked Questions

What does TestCacheEvictionPropagatesRequestContextToDelete() do?
TestCacheEvictionPropagatesRequestContextToDelete() is a function in the fiber codebase, defined in middleware/cache/cache_test.go.
Where is TestCacheEvictionPropagatesRequestContextToDelete() defined?
TestCacheEvictionPropagatesRequestContextToDelete() is defined in middleware/cache/cache_test.go at line 325.
What does TestCacheEvictionPropagatesRequestContextToDelete() call?
TestCacheEvictionPropagatesRequestContextToDelete() 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