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)
| 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 | |
| 192 | func 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") |
nothing calls this directly
no test coverage detected