MCPcopy
hub / github.com/rclone/rclone / TestDirCreate

Function TestDirCreate

vfs/dir_test.go:346–386  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

344}
345
346func TestDirCreate(t *testing.T) {
347 _, vfs, dir, _ := dirCreate(t)
348
349 origModTime := dir.ModTime()
350 time.Sleep(100 * time.Millisecond) // for low rez Windows timers
351 file, err := dir.Create("potato", os.O_WRONLY|os.O_CREATE)
352 require.NoError(t, err)
353 assert.Equal(t, int64(0), file.Size())
354 assert.True(t, dir.ModTime().After(origModTime))
355
356 fd, err := file.Open(os.O_WRONLY | os.O_CREATE)
357 require.NoError(t, err)
358
359 // FIXME Note that this fails with the current implementation
360 // until the file has been opened.
361
362 // file2, err := vfs.Stat("dir/potato")
363 // require.NoError(t, err)
364 // assert.Equal(t, file, file2)
365
366 n, err := fd.Write([]byte("hello"))
367 require.NoError(t, err)
368 assert.Equal(t, 5, n)
369
370 require.NoError(t, fd.Close())
371
372 file2, err := vfs.Stat("dir/potato")
373 require.NoError(t, err)
374 assert.Equal(t, int64(5), file2.Size())
375
376 // Try creating the file again - make sure we get the same file node
377 file3, err := dir.Create("potato", os.O_RDWR|os.O_CREATE)
378 require.NoError(t, err)
379 assert.Equal(t, int64(5), file3.Size())
380 assert.Equal(t, fmt.Sprintf("%p", file), fmt.Sprintf("%p", file3), "didn't return same node")
381
382 // Test read only fs creating new
383 vfs.Opt.ReadOnly = true
384 _, err = dir.Create("sausage", os.O_WRONLY|os.O_CREATE)
385 assert.Equal(t, EROFS, err)
386}
387
388func TestDirMkdir(t *testing.T) {
389 r, vfs, dir, file1 := dirCreate(t)

Callers

nothing calls this directly

Calls 9

dirCreateFunction · 0.85
ModTimeMethod · 0.65
CreateMethod · 0.65
SizeMethod · 0.65
OpenMethod · 0.65
WriteMethod · 0.65
CloseMethod · 0.65
StatMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…