TestPutStreamOversizedObject documents that an object larger than maxBytes is stored anyway (the eviction loop drains the cache but stops when empty), so a single huge range is never silently dropped.
(t *testing.T)
| 311 | t.Fatal(err) |
| 312 | } |
| 313 | if err := os.Mkdir(filepath.Join(dir, tmpSubdir), 0750); err != nil { |
| 314 | t.Fatal(err) |
| 315 | } |
| 316 | if err := os.WriteFile(filepath.Join(dir, tmpSubdir, "interrupted"), []byte("temporary"), 0600); err != nil { |
| 317 | t.Fatal(err) |
| 318 | } |
| 319 | invalid := filepath.Join(dir, "not-a-cache-key") |
| 320 | if err := os.WriteFile(invalid, []byte("external"), 0600); err != nil { |
| 321 | t.Fatal(err) |
| 322 | } |
| 323 | |
| 324 | beforeTemporary := counterValue(t, cacheTemporaryFilesRemovedTotal) |
| 325 | beforeInvalid := counterValue(t, cacheStartupInvalidFilesTotal) |
| 326 | c, err := NewDiskCache(dir, 80, DiskCacheOptions{CapacityProvider: func(string) (diskSpace, error) { |
| 327 | return diskSpace{TotalBytes: 1000, FreeBytes: 990}, nil |
| 328 | }}) |
| 329 | if err != nil { |
| 330 | t.Fatal(err) |
| 331 | } |
| 332 | if !c.Has(key) { |
| 333 | t.Fatal("committed cache entry was not loaded") |
| 334 | } |
| 335 | if _, err := os.Stat(filepath.Join(dir, tmpSubdir, "interrupted")); !os.IsNotExist(err) { |
nothing calls this directly
no test coverage detected