MCPcopy
hub / github.com/rclone/rclone / TestCacheOpenMkdir

Function TestCacheOpenMkdir

vfs/vfscache/cache_test.go:246–291  ·  view source on GitHub ↗

test the open, createItemDir, purge, close, purge sequence

(t *testing.T)

Source from the content-addressed store, hash-verified

244
245// test the open, createItemDir, purge, close, purge sequence
246func 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
293func TestCachePurgeOld(t *testing.T) {
294 _, c := newTestCache(t)

Callers

nothing calls this directly

Calls 14

newTestCacheFunction · 0.85
itemAsStringFunction · 0.85
assertPathExistFunction · 0.85
assertPathNotExistFunction · 0.85
ItemMethod · 0.80
createItemDirMethod · 0.80
BaseMethod · 0.80
DirMethod · 0.80
purgeOldMethod · 0.80
purgeEmptyDirsMethod · 0.80
OpenMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…