MCPcopy Create free account
hub / github.com/go-dev-frame/sponge / TestMemoryCacheError

Function TestMemoryCacheError

pkg/cache/memory_test.go:96–138  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

94}
95
96func TestMemoryCacheError(t *testing.T) {
97 c := newMemoryCache()
98 defer c.Close()
99 testData := c.TestDataSlice[0].(*memoryUser)
100 iCache := c.ICache.(Cache)
101
102 // Set empty key error test
103 key := utils.Uint64ToStr(testData.ID)
104 err := iCache.Set(c.Ctx, "", c.TestDataMap[key], time.Minute)
105 assert.Error(t, err)
106
107 // Set empty value error test
108 key = utils.Uint64ToStr(testData.ID)
109 err = iCache.Set(c.Ctx, key, nil, time.Minute)
110 assert.Error(t, err)
111
112 // Get empty key error test
113 val := &memoryUser{}
114 err = iCache.Get(c.Ctx, "", val)
115 assert.Error(t, err)
116
117 // Get empty result test
118 key = utils.Uint64ToStr(testData.ID)
119 err = iCache.Get(c.Ctx, key, val)
120 assert.NoError(t, err)
121
122 // Get result error test
123 key = utils.Uint64ToStr(testData.ID)
124 _ = iCache.Set(c.Ctx, key, c.TestDataMap[key], time.Minute)
125 time.Sleep(time.Millisecond)
126 err = iCache.Get(c.Ctx, key, nil)
127 assert.Error(t, err)
128
129 // Del empty key error test
130 err = iCache.Del(c.Ctx)
131 assert.NoError(t, err)
132 err = iCache.Del(c.Ctx, "")
133 assert.Error(t, err)
134
135 // empty key test
136 err = iCache.SetCacheWithNotFound(c.Ctx, "")
137 assert.Error(t, err)
138}
139
140func BenchmarkGetFromMemory(b *testing.B) {
141 c := newMemoryCache()

Callers

nothing calls this directly

Calls 8

Uint64ToStrFunction · 0.92
newMemoryCacheFunction · 0.85
CloseMethod · 0.65
SetMethod · 0.65
ErrorMethod · 0.65
GetMethod · 0.65
DelMethod · 0.65
SetCacheWithNotFoundMethod · 0.65

Tested by

no test coverage detected