(t *testing.T, cache *BufferCache, key string, want []byte)
| 30 | } |
| 31 | |
| 32 | func assertKeyValue(t *testing.T, cache *BufferCache, key string, want []byte) { |
| 33 | t.Helper() |
| 34 | |
| 35 | loc, ok := cache.m.m[key] |
| 36 | if !ok { |
| 37 | t.Fatalf(`key "%s" not found in location map`, key) |
| 38 | } |
| 39 | |
| 40 | var ( |
| 41 | buf []byte |
| 42 | compressed bool |
| 43 | ) |
| 44 | switch { |
| 45 | case loc.isCold(): |
| 46 | bidx, cidx := loc.coldBucketIdx(), loc.coldCellIdx() |
| 47 | buf, compressed = cache.cold.buckets[bidx].get(cidx) |
| 48 | case loc.isHot(): |
| 49 | buf = cache.hot.m[key] |
| 50 | |
| 51 | // Ensure there's only one buffer |
| 52 | prefix := binary.LittleEndian.Uint32(buf[:4]) |
| 53 | buflen := prefix & 0x7fffffff |
| 54 | compressed = (prefix & 0x80000000) != 0 |
| 55 | buf = buf[4:] |
| 56 | if int(buflen) != len(buf) { |
| 57 | t.Fatalf("assertKeyValue only compares single buffer: got buflen != len(buf[4:])") |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | if compressed { |
| 62 | buf = cache.decomp.uncompressSimple(buf) |
| 63 | } |
| 64 | if !bytes.Equal(buf, want) { |
| 65 | t.Errorf(`buffers don't match for key "%s", got = %s, want %s`, key, buf, want) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | func assertKeyNotInCache(t *testing.T, cache *BufferCache, key string) { |
| 70 | t.Helper() |
no test coverage detected