MCPcopy Create free account
hub / github.com/MertJSX/folderhost / TestCache_Clear

Function TestCache_Clear

test/cache_test.go:66–97  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

64}
65
66func TestCache_Clear(t *testing.T) {
67 cache := createTestCache(t)
68
69 items := map[string]string{
70 "key1": "value1",
71 "key2": "value2",
72 "key3": "value3",
73 }
74
75 for key, value := range items {
76 cache.Set(key, value, time.Minute)
77 }
78
79 for key := range items {
80 _, ok := cache.Get(key)
81 require.True(t, ok, "All items should exist before clear")
82 }
83
84 cache.Clear()
85
86 for key := range items {
87 _, ok := cache.Get(key)
88 assert.False(t, ok, "No items should exist after clear")
89 }
90
91 t.Run("should be empty after clear", func(t *testing.T) {
92 cache.Set("new-key", "new-value", time.Minute)
93 got, ok := cache.Get("new-key")
94 assert.True(t, ok)
95 assert.Equal(t, "new-value", got, "Should work normally after clear")
96 })
97}
98
99func TestCache_Expiration(t *testing.T) {
100 if testing.Short() {

Callers

nothing calls this directly

Calls 4

createTestCacheFunction · 0.85
SetMethod · 0.80
GetMethod · 0.80
ClearMethod · 0.45

Tested by

no test coverage detected