Skip to content

Commit be4954f

Browse files
committed
tests: add dsync hardlinks corner test cases
Add more dsync test cases to cover more corner cases when reference files are changed in source tree.
1 parent fd4bc1e commit be4954f

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

test/tests/test_dsync.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,39 @@ def test_dsync_hardlink_dest_ref_changed(self):
365365
with open(self.dst / filename, "r") as fh:
366366
self.assertEqual(fh.read(), "original")
367367

368+
def test_dsync_hardlink_dest_multiple_ref_changed(self):
369+
# Create a conflicting file in dest with different content and check it
370+
# is overwritten.
371+
with open(self.src / "file3", "w+") as fh:
372+
fh.write("original3")
373+
with open(self.src / "file4", "w+") as fh:
374+
fh.write("original4")
375+
self.run_dsync()
376+
with open(self.dst / "file3", "w+") as fh:
377+
fh.write("modified3")
378+
with open(self.dst / "file4", "w+") as fh:
379+
fh.write("modified4")
380+
proc = self.run_dsync()
381+
self.assertInProcStdout(
382+
proc,
383+
textwrap.dedent(
384+
"""
385+
Items: 5
386+
Directories: 0
387+
Files: 2
388+
Links: 0
389+
Hardlinks: 3
390+
"""
391+
),
392+
)
393+
self.assertSrcDstEqual()
394+
for filename in ["file3", "hardlink3"]:
395+
with open(self.dst / filename, "r") as fh:
396+
self.assertEqual(fh.read(), "original3")
397+
for filename in ["file4", "hardlink4.0", "hardlink4.1"]:
398+
with open(self.dst / filename, "r") as fh:
399+
self.assertEqual(fh.read(), "original4")
400+
368401
def test_dsync_hardlink_outside_tree(self):
369402
# Create temporary file outside src and dst tree, create hardlink in src
370403
# to this temporary file, sync and check. The destination should contain
@@ -415,6 +448,27 @@ def test_dsync_change_hardlink_dest(self):
415448
)
416449
self.assertSrcDstEqual()
417450

451+
def test_dsync_hardlink_src_ref_replaced(self):
452+
# Synchronize, replace reference file in source, re-synchronize and
453+
# check.
454+
self.run_dsync()
455+
(self.src / "file3").unlink()
456+
create_file(self.src / "file3")
457+
proc = self.run_dsync()
458+
self.assertInProcStdout(
459+
proc,
460+
textwrap.dedent(
461+
"""
462+
Items: 2
463+
Directories: 0
464+
Files: 2
465+
Links: 0
466+
Hardlinks: 0
467+
"""
468+
),
469+
)
470+
self.assertSrcDstEqual()
471+
418472
def test_dsync_add_hardlink_same_inode(self):
419473
# Synchronize, add hardlink on inode which has already multiple links,
420474
# re-synchronize and check.

0 commit comments

Comments
 (0)