test the open, createItemDir, purge, close, purge sequence
(t *testing.T)
| 244 | |
| 245 | // test the open, createItemDir, purge, close, purge sequence |
| 246 | func TestCacheOpenMkdir(t *testing.T) { |
| 247 | _, c := newTestCache(t) |
| 248 | |
| 249 | // open |
| 250 | potato := c.Item("sub/potato") |
| 251 | require.NoError(t, potato.Open(nil)) |
| 252 | |
| 253 | assert.Equal(t, []string{ |
| 254 | `name="sub/potato" opens=1 size=0`, |
| 255 | }, itemAsString(c)) |
| 256 | |
| 257 | // createItemDir |
| 258 | p, err := c.createItemDir("sub/potato") |
| 259 | require.NoError(t, err) |
| 260 | assert.Equal(t, "potato", filepath.Base(p)) |
| 261 | assert.Equal(t, []string{ |
| 262 | `name="sub/potato" opens=1 size=0`, |
| 263 | }, itemAsString(c)) |
| 264 | |
| 265 | // test directory exists |
| 266 | fi := assertPathExist(t, filepath.Dir(p)) |
| 267 | assert.True(t, fi.IsDir()) |
| 268 | |
| 269 | // clean the cache |
| 270 | c.purgeOld(-10 * time.Second) |
| 271 | |
| 272 | // test directory still exists |
| 273 | fi = assertPathExist(t, filepath.Dir(p)) |
| 274 | assert.True(t, fi.IsDir()) |
| 275 | |
| 276 | // close |
| 277 | require.NoError(t, potato.Close(nil)) |
| 278 | |
| 279 | assert.Equal(t, []string{ |
| 280 | `name="sub/potato" opens=0 size=0`, |
| 281 | }, itemAsString(c)) |
| 282 | |
| 283 | // clean the cache |
| 284 | c.purgeOld(-10 * time.Second) |
| 285 | c.purgeEmptyDirs("", true) |
| 286 | |
| 287 | assert.Equal(t, []string(nil), itemAsString(c)) |
| 288 | |
| 289 | // test directory does not exist |
| 290 | assertPathNotExist(t, filepath.Dir(p)) |
| 291 | } |
| 292 | |
| 293 | func TestCachePurgeOld(t *testing.T) { |
| 294 | _, c := newTestCache(t) |
nothing calls this directly
no test coverage detected
searching dependent graphs…