Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

bisync: check that listings match the paths after each run

nielash81d7b6f29933
diff --git a/cmd/bisync/bisync_test.go b/cmd/bisync/bisync_test.go
index f360bab05..8e6999d6c 100644
--- a/cmd/bisync/bisync_test.go
+++ b/cmd/bisync/bisync_test.go
@@ -192,6 +192,8 @@ type bisyncTest struct {
step int
stopped bool
stepStr string
+ stepName string
+ testTitle string
testCase string
sessionName string
// test dirs
@@ -544,6 +546,10 @@ func (b *bisyncTest) runTestCase(ctx context.Context, t *testing.T, testCase str
b.step++
b.stepStr = fmt.Sprintf("(%02d) :", b.step)
line = scenReplacer.Replace(line)
+ if strings.HasPrefix(line, "test ") {
+ b.testTitle = line
+ }
+ b.stepName = fmt.Sprintf("%s (%02d) %s", b.testTitle, b.step, line)
if err = b.runTestStep(ctx, line); err != nil {
require.Failf(b.t, "test step failed", "step %d failed: %v", b.step, err)
return
@@ -610,6 +616,10 @@ func (b *bisyncTest) runTestCase(ctx context.Context, t *testing.T, testCase str
passed = true
}
}
+ if passed && b.t.Failed() {
+ msg = color(terminal.RedFg, fmt.Sprintf("TEST %s FAILED - see errors above", b.testCase))
+ passed = false
+ }
b.t.Log(msg)
if !passed {
b.t.FailNow()
@@ -1241,9 +1251,51 @@ func (b *bisyncTest) runBisync(ctx context.Context, args []string) (err error) {
if err != nil {
b.logPrintf("Bisync error: %v", err)
}
+ if err == nil && !opt.DryRun && opt.TestFn == nil && opt.FiltersFile == "" {
+ b.checkListingsMatchRemotes(ctx, fs1, fs2)
+ }
return nil
}
+// checkListingsMatchRemotes checks that after a successful run the files
+// named in each listing are exactly the files on that path.
+func (b *bisyncTest) checkListingsMatchRemotes(ctx context.Context, fs1, fs2 fs.Fs) {
+ session := bilib.SessionName(fs1, fs2)
+ for i, f := range []fs.Fs{fs1, fs2} {
+ listing := filepath.Join(b.workDir, fmt.Sprintf("%s.path%d.lst", session, i+1))
+ data, err := os.ReadFile(listing)
+ if err != nil {
+ listing = filepath.Join(b.workDir, fmt.Sprintf("%s.path%d.lst", norm.NFC.String(session), i+1))
+ if data, err = os.ReadFile(listing); err != nil {
+ b.t.Logf("invariant: skipping, can't read listing: %v", err)
+ return
+ }
+ }
+ inListing := bilib.Names{}
+ for line := range strings.SplitSeq(string(data), "\n") {
+ if line == "" || strings.HasPrefix(line, "#") || strings.HasPrefix(line, "d ") {
+ continue
+ }
+ q := strings.Index(line, `"`)
+ name, err := strconv.Unquote(line[q:])
+ require.NoError(b.t, err, "parsing listing line %q", line)
+ inListing.Add(name)
+ }
+ onRemote := bilib.Names{}
+ require.NoError(b.t, operations.ListFn(ctx, f, func(o fs.Object) { onRemote.Add(o.Remote()) }))
+ for _, name := range onRemote.ToList() {
+ if !inListing.Has(name) {
+ b.t.Errorf("invariant: step %q: Path%d has %q but its listing does not", b.stepName, i+1, name)
+ }
+ }
+ for _, name := range inListing.ToList() {
+ if !onRemote.Has(name) {
+ b.t.Errorf("invariant: step %q: Path%d listing has %q but the path does not", b.stepName, i+1, name)
+ }
+ }
+ }
+}
+
// saveTestListings creates a copy of test artifacts with given prefix
// including listings (.lst*), queues (.que) and filters (.flt, .flt.md5)
func (b *bisyncTest) saveTestListings(prefix string, keepSource bool) (err error) {