(t *testing.T)
| 94 | } |
| 95 | |
| 96 | func 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 | |
| 140 | func BenchmarkGetFromMemory(b *testing.B) { |
| 141 | c := newMemoryCache() |
nothing calls this directly
no test coverage detected