MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestRedisCache

Function TestRedisCache

pkg/chunk/cache/redis_cache_test.go:14–51  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestRedisCache(t *testing.T) {
15 c, err := mockRedisCache()
16 require.Nil(t, err)
17 defer c.redis.Close()
18
19 keys := []string{"key1", "key2", "key3"}
20 bufs := [][]byte{[]byte("data1"), []byte("data2"), []byte("data3")}
21 miss := []string{"miss1", "miss2"}
22
23 // ensure input correctness
24 nHit := len(keys)
25 require.Len(t, bufs, nHit)
26
27 nMiss := len(miss)
28
29 ctx := context.Background()
30
31 c.Store(ctx, keys, bufs)
32
33 // test hits
34 found, data, missed := c.Fetch(ctx, keys)
35
36 require.Len(t, found, nHit)
37 require.Len(t, missed, 0)
38 for i := range nHit {
39 require.Equal(t, keys[i], found[i])
40 require.Equal(t, bufs[i], data[i])
41 }
42
43 // test misses
44 found, _, missed = c.Fetch(ctx, miss)
45
46 require.Len(t, found, 0)
47 require.Len(t, missed, nMiss)
48 for i := range nMiss {
49 require.Equal(t, miss[i], missed[i])
50 }
51}
52
53func mockRedisCache() (*RedisCache, error) {
54 redisServer, err := miniredis.Run()

Callers

nothing calls this directly

Calls 6

mockRedisCacheFunction · 0.85
CloseMethod · 0.65
StoreMethod · 0.65
FetchMethod · 0.65
EqualMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected