(t *testing.T)
| 26 | } |
| 27 | |
| 28 | func 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 | |
| 60 | func getRedisCacheAndServer(t *testing.T) (*redisCache, *miniredis.Miniredis) { |
| 61 | s := miniredis.RunT(t) |
nothing calls this directly
no test coverage detected