From 7e41408815c893decbe287204e1d626895f7afdf Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Sun, 20 Nov 2022 20:58:45 +0000 Subject: [PATCH] Add test for incremental backup with mid delete Just for validation that delete does the right thing --- .../datmantests/test_backup_and_extract.py | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/testsuite/datmantests/test_backup_and_extract.py b/testsuite/datmantests/test_backup_and_extract.py index cb194c4..8bb5d22 100644 --- a/testsuite/datmantests/test_backup_and_extract.py +++ b/testsuite/datmantests/test_backup_and_extract.py @@ -299,3 +299,79 @@ kind = {{ stdout = "blahblah.txt" }} ) td.cleanup() + + def test_backup_incremental_with_mid_delete(self): + td = TemporaryDirectory("test_backup_incremental_with_mid_delete") + tdpath = Path(td.name) + + datman_path = tdpath.joinpath("datman") + src_path = datman_path.joinpath("srca") + yama_path = datman_path.joinpath("main") + + set_up_simple_datman(datman_path) + set_up_simple_yama(yama_path) + + rng = Random() + seed = rng.randint(0, 9001) + print(f"seed: {seed}") + rng.seed(seed) + initial_descriptor, _ = generate_random_dir(rng, src_path, 32) + + print("storing") + subprocess.check_call(("datman", "backup-one", "srca", "main"), cwd=datman_path) + + # now mutate and store incremental + randomly_mutate_directory_in_descriptor(initial_descriptor, src_path, rng) + time.sleep(2) + subprocess.check_call(("datman", "backup-one", "srca", "main"), cwd=datman_path) + + # now mutate and store incremental again! + randomly_mutate_directory_in_descriptor(initial_descriptor, src_path, rng) + mutated_descriptor = scan_dir(src_path) + time.sleep(2) + subprocess.check_call(("datman", "backup-one", "srca", "main"), cwd=datman_path) + + pointer_names = ( + subprocess.check_output(("yama", "debug", "lsp"), cwd=yama_path) + .decode() + .split("\n") + ) + self.assertEqual(len(pointer_names), 3) + self.assertLess(pointer_names[0], pointer_names[1]) + self.assertLess(pointer_names[1], pointer_names[2]) + + print(f"removing mid pointer {pointer_names[1]}") + subprocess.check_call( + ("yama", "debug", "rmp", pointer_names[1]), + cwd=yama_path, + ) + + print("extracting last pointer to check still valid") + dest_path = tdpath.joinpath("desta") + subprocess.check_call( + ( + "datman", + "extract", + "--skip-metadata", + "--accept-partial", + "main", + "../desta", + ), + cwd=datman_path, + ) + + # this will be wrapped in a directory that starts with the name srca+ + extracted_dir_descriptor_wrapper = scan_dir(dest_path) + + contents = extracted_dir_descriptor_wrapper.contents + self.assertEqual(len(contents), 1) + key, value = next(iter(contents.items())) + self.assertTrue(key.startswith("srca+")) + + self.assertIsInstance(value, DirectoryDescriptor) + key, value = next(iter(value.contents.items())) + self.assertEqual(key, "srca") + + self.assertEqual(value.ignore_metadata(), mutated_descriptor.ignore_metadata()) + + td.cleanup()