MCPcopy Create free account
hub / github.com/AdRoll/baker / assertKeyValue

Function assertKeyValue

pkg/buffercache/helper_test.go:32–67  ·  view source on GitHub ↗
(t *testing.T, cache *BufferCache, key string, want []byte)

Source from the content-addressed store, hash-verified

30}
31
32func 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
69func assertKeyNotInCache(t *testing.T, cache *BufferCache, key string) {
70 t.Helper()

Calls 6

isColdMethod · 0.80
coldBucketIdxMethod · 0.80
coldCellIdxMethod · 0.80
isHotMethod · 0.80
uncompressSimpleMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected