MCPcopy
hub / github.com/rclone/rclone / runTestCase

Method runTestCase

cmd/bisync/bisync_test.go:429–614  ·  view source on GitHub ↗
(ctx context.Context, t *testing.T, testCase string)

Source from the content-addressed store, hash-verified

427}
428
429func (b *bisyncTest) runTestCase(ctx context.Context, t *testing.T, testCase string) {
430 b.t = t
431 b.testCase = testCase
432 var err error
433
434 b.fs1, b.parent1, b.path1, b.canonPath1 = b.makeTempRemote(ctx, b.argRemote1, "path1")
435 b.fs2, b.parent2, b.path2, b.canonPath2 = b.makeTempRemote(ctx, b.argRemote2, "path2")
436
437 if strings.Contains(b.replaceHex(b.path1), " ") || strings.Contains(b.replaceHex(b.path2), " ") {
438 b.t.Skip("skipping as tests can't handle spaces config string")
439 }
440
441 b.sessionName = bilib.SessionName(b.fs1, b.fs2)
442 b.testDir = b.ensureDir(b.dataRoot, "test_"+b.testCase, false)
443 b.initDir = b.ensureDir(b.testDir, "initial", false)
444 b.goldenDir = b.ensureDir(b.testDir, "golden", false)
445 b.dataDir = b.ensureDir(b.testDir, "modfiles", true) // optional
446
447 // normalize unicode so tets are runnable on macOS
448 b.sessionName = norm.NFC.String(b.sessionName)
449 b.goldenDir = norm.NFC.String(b.goldenDir)
450
451 // For test stability, jam initial dates to a fixed past date.
452 // Test cases that change files will touch specific files to fixed new dates.
453 err = filepath.Walk(b.initDir, func(path string, info os.FileInfo, err error) error {
454 if err == nil && !info.IsDir() {
455 return os.Chtimes(path, initDate, initDate)
456 }
457 return err
458 })
459 require.NoError(b.t, err, "jamming initial dates")
460
461 // copy to a new unique initdir and datadir so concurrent tests don't interfere with each other
462 ctxNoDsStore, _ := ctxNoDsStore(ctx, b.t)
463 makeUnique := func(label, oldPath string) (newPath string) {
464 newPath = oldPath
465 info, err := os.Stat(oldPath)
466 if err == nil && info.IsDir() { // datadir is optional
467 oldFs, err := cache.Get(ctx, oldPath)
468 require.NoError(b.t, err)
469 newPath = b.tempDir + "/" + label + "/" + "test_" + b.testCase + "-" + random.String(8)
470 newFs, err := cache.Get(ctx, newPath)
471 require.NoError(b.t, err)
472 require.NoError(b.t, sync.CopyDir(ctxNoDsStore, newFs, oldFs, true), "setting up "+label)
473 }
474 return newPath
475 }
476 b.initDir = makeUnique("initdir", b.initDir)
477 b.dataDir = makeUnique("datadir", b.dataDir)
478
479 // Prepare initial content
480 b.cleanupCase(ctx)
481 ctx = accounting.WithStatsGroup(ctx, random.String(8))
482 fstest.CheckListingWithPrecision(b.t, b.fs1, []fstest.Item{}, []string{}, b.fs1.Precision()) // verify starting from empty
483 fstest.CheckListingWithPrecision(b.t, b.fs2, []fstest.Item{}, []string{}, b.fs2.Precision())
484 initFs, err := cache.Get(ctx, b.initDir)
485 require.NoError(b.t, err)
486

Callers 1

testBisyncFunction · 0.80

Calls 15

makeTempRemoteMethod · 0.95
replaceHexMethod · 0.95
ensureDirMethod · 0.95
cleanupCaseMethod · 0.95
mkdirMethod · 0.95
newReplacerMethod · 0.95
runTestStepMethod · 0.95
logPrintfMethod · 0.95
storeGoldenMethod · 0.95
compareResultsMethod · 0.95
SessionNameFunction · 0.92
GetFunction · 0.92

Tested by

no test coverage detected