MCPcopy
hub / github.com/rclone/rclone / TestCopyFileMaxTransfer

Function TestCopyFileMaxTransfer

fs/operations/copy_test.go:457–534  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

455}
456
457func TestCopyFileMaxTransfer(t *testing.T) {
458 ctx := context.Background()
459 ctx, ci := fs.AddConfig(ctx)
460 r := fstest.NewRun(t)
461 defer accounting.Stats(ctx).ResetCounters()
462
463 const sizeCutoff = 2048
464
465 // Make random incompressible data
466 randomData := make([]byte, sizeCutoff)
467 _, err := rand.Read(randomData)
468 require.NoError(t, err)
469 randomString := string(randomData)
470
471 file1 := r.WriteFile("TestCopyFileMaxTransfer/file1", "file1 contents", t1)
472 file2 := r.WriteFile("TestCopyFileMaxTransfer/file2", "file2 contents"+randomString, t2)
473 file3 := r.WriteFile("TestCopyFileMaxTransfer/file3", "file3 contents"+randomString, t2)
474 file4 := r.WriteFile("TestCopyFileMaxTransfer/file4", "file4 contents"+randomString, t2)
475
476 // Cutoff mode: Hard
477 ci.MaxTransfer = sizeCutoff
478 ci.CutoffMode = fs.CutoffModeHard
479
480 if runtime.GOOS == "darwin" {
481 // disable server-side copies as they don't count towards transfer size stats
482 r.Flocal.Features().Disable("Copy")
483 if r.Fremote.Features().IsLocal {
484 r.Fremote.Features().Disable("Copy")
485 }
486 }
487
488 // file1: Show a small file gets transferred OK
489 accounting.Stats(ctx).ResetCounters()
490 err = operations.CopyFile(ctx, r.Fremote, r.Flocal, file1.Path, file1.Path)
491 require.NoError(t, err)
492 r.CheckLocalItems(t, file1, file2, file3, file4)
493 r.CheckRemoteItems(t, file1)
494
495 // file2: show a large file does not get transferred
496 accounting.Stats(ctx).ResetCounters()
497 err = operations.CopyFile(ctx, r.Fremote, r.Flocal, file2.Path, file2.Path)
498 require.NotNil(t, err, "Did not get expected max transfer limit error")
499 if !errors.Is(err, accounting.ErrorMaxTransferLimitReachedFatal) {
500 t.Log("Expecting error to contain accounting.ErrorMaxTransferLimitReachedFatal")
501 // Sometimes the backends or their SDKs don't pass the
502 // error through properly, so check that it at least
503 // has the text we expect in.
504 assert.Contains(t, err.Error(), "max transfer limit reached")
505 }
506 r.CheckLocalItems(t, file1, file2, file3, file4)
507 r.CheckRemoteItems(t, file1)
508
509 // Cutoff mode: Cautious
510 ci.CutoffMode = fs.CutoffModeCautious
511
512 // file3: show a large file does not get transferred
513 accounting.Stats(ctx).ResetCounters()
514 err = operations.CopyFile(ctx, r.Fremote, r.Flocal, file3.Path, file3.Path)

Callers

nothing calls this directly

Calls 15

WriteFileMethod · 0.95
CheckLocalItemsMethod · 0.95
CheckRemoteItemsMethod · 0.95
AddConfigFunction · 0.92
NewRunFunction · 0.92
StatsFunction · 0.92
CopyFileFunction · 0.92
isChunkerFunction · 0.85
ResetCountersMethod · 0.80
DisableMethod · 0.80
IsMethod · 0.80
LogMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…