MCPcopy Create free account
hub / github.com/ContentSquare/chproxy / TestCacheSize

Function TestCacheSize

cache/redis_cache_test.go:28–58  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26}
27
28func TestCacheSize(t *testing.T) {
29 redisCache := getRedisCache(t)
30 nbKeys := redisCache.nbOfKeys()
31 if nbKeys > 0 {
32 t.Fatalf("the cache should be empty")
33 }
34
35 cacheSize := redisCache.nbOfBytes()
36 if cacheSize > 0 {
37 t.Fatalf("the cache should be empty")
38 }
39
40 buffer := strings.NewReader("an object")
41
42 if _, err := redisCache.Put(buffer, ContentMetadata{}, &Key{Query: []byte("SELECT 1")}); err != nil {
43 t.Fatalf("failed to put it to cache: %s", err)
44 }
45 if _, err := redisCache.Put(buffer, ContentMetadata{}, &Key{Query: []byte("SELECT 2")}); err != nil {
46 t.Fatalf("failed to put it to cache: %s", err)
47 }
48 if _, err := redisCache.Put(buffer, ContentMetadata{}, &Key{Query: []byte("SELECT 2")}); err != nil {
49 t.Fatalf("failed to put it to cache: %s", err)
50 }
51
52 stats := redisCache.Stats()
53 if stats.Items != 2 {
54 t.Fatalf("cache should contain 2 items")
55 }
56 // because of the use of miniredis to simulate a real redis server
57 // we can't check stats.Size because miniredis doesn't handle the memory usage of redis
58}
59
60func getRedisCacheAndServer(t *testing.T) (*redisCache, *miniredis.Miniredis) {
61 s := miniredis.RunT(t)

Callers

nothing calls this directly

Calls 5

getRedisCacheFunction · 0.85
nbOfKeysMethod · 0.80
nbOfBytesMethod · 0.80
PutMethod · 0.65
StatsMethod · 0.65

Tested by

no test coverage detected