(t *testing.T)
| 129 | |
| 130 | // newTestCache creates a DiskCache backed by t.TempDir() for isolation. |
| 131 | func newTestCache(t *testing.T) *DiskCache { |
| 132 | t.Helper() |
| 133 | c, err := NewDiskCache(t.TempDir(), 100) |
| 134 | if err != nil { |
| 135 | t.Fatalf("NewDiskCache: %v", err) |
| 136 | } |
| 137 | return c |
| 138 | } |
| 139 | |
| 140 | func TestDiskCachePutGetHas(t *testing.T) { |
| 141 | c := newTestCache(t) |
| 142 | key := strings.Repeat("a", 64) |
| 143 | data := []byte("hello world") |
| 144 | |
| 145 | if c.Has(key) { |
| 146 | t.Fatal("Has should be false before PutStream") |
| 147 | } |
| 148 | if _, _, ok := c.Open(key); ok { |
| 149 | t.Fatal("Open should miss before PutStream") |
| 150 | } |
| 151 | if _, err := c.PutStream(key, bytes.NewReader(data)); err != nil { |
| 152 | t.Fatalf("PutStream: %v", err) |
| 153 | } |
| 154 | if !c.Has(key) { |
| 155 | t.Fatal("Has should be true after PutStream") |
| 156 | } |
nothing calls this directly
no test coverage detected