MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestDiskCacheEviction

Function TestDiskCacheEviction

cmd/cache-proxy/cache_test.go:176–200  ·  view source on GitHub ↗

TestDiskCacheEviction exercises LRU eviction when the cache fills up. We set maxBytes tiny by construction: NewDiskCache uses statfs * percent, so we directly mutate the cache after construction for a predictable test.

(t *testing.T)

Source from the content-addressed store, hash-verified

174 }
175 r, size, ok := c.Open(key)
176 if !ok {
177 t.Fatal("Open should find entry")
178 }
179 defer func() { _ = r.Close() }()
180 if size != int64(len(data)) {
181 t.Errorf("size = %d, want %d", size, len(data))
182 }
183 got, err := io.ReadAll(r)
184 if err != nil {
185 t.Fatalf("ReadAll: %v", err)
186 }
187 if string(got) != string(data) {
188 t.Errorf("Open data = %q, want %q", got, data)
189 }
190}
191
192func TestDiskCacheRejectsInvalidKey(t *testing.T) {
193 c := newTestCache(t)
194 bad := "../../etc/passwd"
195
196 if c.Has(bad) {
197 t.Error("Has should reject invalid key")
198 }
199 if _, _, ok := c.Open(bad); ok {
200 t.Error("Open should reject invalid key")
201 }
202 if _, err := c.PutStream(bad, bytes.NewReader([]byte("x"))); err == nil {
203 t.Error("PutStream should reject invalid key")

Callers

nothing calls this directly

Calls 4

newTestCacheFunction · 0.85
PutMethod · 0.80
HasMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected