MCPcopy
hub / github.com/rclone/rclone / TestRWFileHandleWriteAt

Function TestRWFileHandleWriteAt

vfs/read_write_test.go:340–388  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

338}
339
340func TestRWFileHandleWriteAt(t *testing.T) {
341 r, vfs, fh := rwHandleCreateWriteOnly(t)
342
343 offset := func() int64 {
344 n, err := fh.Seek(0, io.SeekCurrent)
345 require.NoError(t, err)
346 return n
347 }
348
349 // Name
350 assert.Equal(t, "file1", fh.Name())
351
352 // Preconditions
353 assert.Equal(t, int64(0), offset())
354 assert.True(t, fh.opened)
355 assert.False(t, fh.writeCalled)
356
357 // Write the data
358 n, err := fh.WriteAt([]byte("hello**"), 0)
359 assert.NoError(t, err)
360 assert.Equal(t, 7, n)
361
362 // After write
363 assert.Equal(t, int64(0), offset())
364 assert.True(t, fh.writeCalled)
365
366 // Write more data
367 n, err = fh.WriteAt([]byte(" world"), 5)
368 assert.NoError(t, err)
369 assert.Equal(t, 6, n)
370
371 // Close
372 assert.NoError(t, fh.Close())
373
374 // Check can't write on closed handle
375 n, err = fh.WriteAt([]byte("hello"), 0)
376 assert.Equal(t, ECLOSED, err)
377 assert.Equal(t, 0, n)
378
379 // check vfs
380 root, err := vfs.Root()
381 require.NoError(t, err)
382 checkListing(t, root, []string{"file1,11,false"})
383
384 // check the underlying r.Fremote but not the modtime
385 file1 := fstest.NewItem("file1", "hello world", t1)
386 vfs.WaitForWriters(waitForWritersDelay)
387 fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{file1}, []string{}, fs.ModTimeNotSupported)
388}
389
390func TestRWFileHandleWriteNoWrite(t *testing.T) {
391 r, vfs, fh := rwHandleCreateWriteOnly(t)

Callers

nothing calls this directly

Calls 11

NewItemFunction · 0.92
rwHandleCreateWriteOnlyFunction · 0.85
WaitForWritersMethod · 0.80
checkListingFunction · 0.70
SeekMethod · 0.65
NameMethod · 0.65
WriteAtMethod · 0.65
CloseMethod · 0.65
RootMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…