MCPcopy
hub / github.com/rclone/rclone / testFileReadAt

Function testFileReadAt

vfs/write_test.go:344–377  ·  view source on GitHub ↗
(t *testing.T, n int)

Source from the content-addressed store, hash-verified

342}
343
344func testFileReadAt(t *testing.T, n int) {
345 _, vfs, fh := writeHandleCreate(t)
346
347 contents := []byte(random.String(n))
348 if n != 0 {
349 written, err := fh.Write(contents)
350 require.NoError(t, err)
351 assert.Equal(t, n, written)
352 }
353
354 // Close the file without writing to it if n==0
355 err := fh.Close()
356 if errors.Is(err, fs.ErrorCantUploadEmptyFiles) {
357 t.Logf("skipping test: %v", err)
358 return
359 }
360 assert.NoError(t, err)
361
362 // read the file back in using ReadAt into a buffer
363 // this simulates what mount does
364 rd, err := vfs.OpenFile("file1", os.O_RDONLY, 0)
365 require.NoError(t, err)
366
367 buf := make([]byte, 1024)
368 read, err := rd.ReadAt(buf, 0)
369 if err != io.EOF {
370 assert.NoError(t, err)
371 }
372 assert.Equal(t, read, n)
373 assert.Equal(t, contents, buf[:read])
374
375 err = rd.Close()
376 assert.NoError(t, err)
377}
378
379func TestFileReadAtZeroLength(t *testing.T) {
380 testFileReadAt(t, 0)

Callers 2

TestFileReadAtZeroLengthFunction · 0.85

Calls 9

StringFunction · 0.92
writeHandleCreateFunction · 0.85
IsMethod · 0.80
LogfMethod · 0.80
WriteMethod · 0.65
CloseMethod · 0.65
OpenFileMethod · 0.65
ReadAtMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…