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

Function TestCache_SetAndGet

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

Source from the content-addressed store, hash-verified

10)
11
12func TestCache_SetAndGet(t *testing.T) {
13 cache := createTestCache(t)
14
15 t.Run("should set and get value successfully", func(t *testing.T) {
16 key := "test-key"
17 value := "test-value"
18
19 cache.Set(key, value, time.Minute)
20
21 got, ok := cache.Get(key)
22 assert.True(t, ok, "Get should return true for existing key")
23 assert.Equal(t, value, got, "Get should return correct value")
24 })
25
26 t.Run("should return false for non-existent key", func(t *testing.T) {
27 _, ok := cache.Get("non-existent")
28 assert.False(t, ok, "Get should return false for non-existent key")
29 })
30
31 t.Run("should override existing key", func(t *testing.T) {
32 key := "same-key"
33
34 cache.Set(key, "first-value", time.Minute)
35 cache.Set(key, "second-value", time.Minute)
36
37 got, ok := cache.Get(key)
38 assert.True(t, ok)
39 assert.Equal(t, "second-value", got, "Should return last set value")
40 })
41}
42
43func TestCache_Delete(t *testing.T) {
44 cache := createTestCache(t)

Callers

nothing calls this directly

Calls 3

createTestCacheFunction · 0.85
SetMethod · 0.80
GetMethod · 0.80

Tested by

no test coverage detected