(t *testing.T)
| 220 | for _, k := range keys { |
| 221 | if _, err := c.PutStream(k, bytes.NewReader(make([]byte, 60))); err != nil { |
| 222 | t.Fatalf("PutStream %s: %v", k, err) |
| 223 | } |
| 224 | } |
| 225 | // After three 60-byte puts with maxBytes=100, the first key must have |
| 226 | // been evicted (oldest lastAccess). |
| 227 | if c.Has(keys[0]) { |
| 228 | t.Error("oldest entry should have been evicted") |
| 229 | } |
| 230 | // The most recent must still be present. |
| 231 | if !c.Has(keys[2]) { |
| 232 | t.Error("newest entry should still be cached") |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | func TestDiskCacheEntryLimitEvictsOldest(t *testing.T) { |
| 237 | c := newTestCache(t) |
| 238 | c.maxEntries = 2 |
| 239 | keys := []string{strings.Repeat("4", 64), strings.Repeat("5", 64), strings.Repeat("6", 64)} |
| 240 | for _, key := range keys { |
| 241 | if _, err := c.PutStream(key, bytes.NewReader([]byte("x"))); err != nil { |
| 242 | t.Fatal(err) |
| 243 | } |
| 244 | } |
| 245 | if c.order.Len() != 2 || c.Has(keys[0]) || !c.Has(keys[1]) || !c.Has(keys[2]) { |
| 246 | t.Fatalf("entry-limited cache retained unexpected keys: len=%d first=%t second=%t third=%t", c.order.Len(), c.Has(keys[0]), c.Has(keys[1]), c.Has(keys[2])) |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | func TestDiskCacheHardEntryLimitAppliesDuringStartupScan(t *testing.T) { |
| 251 | dir := t.TempDir() |
| 252 | entries := []struct { |
| 253 | key string |
| 254 | when time.Time |
| 255 | }{ |
nothing calls this directly
no test coverage detected