From 4505c90920faa984058800829dca1ffb27e4bc2a Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sat, 15 Apr 2023 16:46:23 +0200 Subject: [PATCH] tests: use a smaller dir for src_dir, fixes #7518 also: introduce src_file, which is a file in src_dir. --- src/borg/testsuite/archiver/__init__.py | 4 +++- src/borg/testsuite/archiver/check_cmd.py | 13 +++++++------ src/borg/testsuite/archiver/delete_cmd.py | 3 ++- src/borg/testsuite/archiver/mount_cmds.py | 12 +++--------- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/borg/testsuite/archiver/__init__.py b/src/borg/testsuite/archiver/__init__.py index b10cee76f..932dc0f9c 100644 --- a/src/borg/testsuite/archiver/__init__.py +++ b/src/borg/testsuite/archiver/__init__.py @@ -33,7 +33,9 @@ RK_ENCRYPTION = "--encryption=repokey-aes-ocb" KF_ENCRYPTION = "--encryption=keyfile-chacha20-poly1305" -src_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) +# this points to src/borg/archiver directory (which is small and has only a few files) +src_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "archiver")) +src_file = "archiver/__init__.py" # relative path of one file in src_dir requires_hardlinks = pytest.mark.skipif(not are_hardlinks_supported(), reason="hardlinks not supported") diff --git a/src/borg/testsuite/archiver/check_cmd.py b/src/borg/testsuite/archiver/check_cmd.py index 4bd989eba..023a983d6 100644 --- a/src/borg/testsuite/archiver/check_cmd.py +++ b/src/borg/testsuite/archiver/check_cmd.py @@ -10,6 +10,7 @@ from ...manifest import Manifest from ...repository import Repository from . import ArchiverTestCaseBase, RemoteArchiverTestCaseBase, ArchiverTestCaseBinaryBase, RK_ENCRYPTION, BORG_EXES +from . import src_file class ArchiverCheckTestCase(ArchiverTestCaseBase): @@ -95,7 +96,7 @@ def test_missing_file_chunk(self): archive, repository = self.open_archive("archive1") with repository: for item in archive.iter_items(): - if item.path.endswith("testsuite/archiver/__init__.py"): + if item.path.endswith(src_file): valid_chunks = item.chunks killed_chunk = valid_chunks[-1] repository.delete(killed_chunk.id) @@ -116,7 +117,7 @@ def test_missing_file_chunk(self): archive, repository = self.open_archive(archive_name) with repository: for item in archive.iter_items(): - if item.path.endswith("testsuite/archiver/__init__.py"): + if item.path.endswith(src_file): self.assert_not_equal(valid_chunks, item.chunks) self.assert_not_in(killed_chunk, item.chunks) break @@ -128,13 +129,13 @@ def test_missing_file_chunk(self): # check should be able to heal the file now: output = self.cmd(f"--repo={self.repository_location}", "check", "-v", "--repair", exit_code=0) self.assert_in("Healed previously missing file chunk", output) - self.assert_in("testsuite/archiver/__init__.py: Completely healed previously damaged file!", output) + self.assert_in(f"{src_file}: Completely healed previously damaged file!", output) # check that the file in the old archives has the correct chunks again for archive_name in ("archive1", "archive2"): archive, repository = self.open_archive(archive_name) with repository: for item in archive.iter_items(): - if item.path.endswith("testsuite/archiver/__init__.py"): + if item.path.endswith(src_file): self.assert_equal(valid_chunks, item.chunks) break else: @@ -251,7 +252,7 @@ def _test_verify_data(self, *init_args): archive, repository = self.open_archive("archive1") with repository: for item in archive.iter_items(): - if item.path.endswith("testsuite/archiver/__init__.py"): + if item.path.endswith(src_file): chunk = item.chunks[-1] data = repository.get(chunk.id) data = data[0:100] + b"x" + data[101:] @@ -264,7 +265,7 @@ def _test_verify_data(self, *init_args): # repair (heal is tested in another test) output = self.cmd(f"--repo={self.repository_location}", "check", "--repair", "--verify-data", exit_code=0) assert bin_to_hex(chunk.id) + ", integrity error" in output - assert "testsuite/archiver/__init__.py: New missing file chunk detected" in output + assert f"{src_file}: New missing file chunk detected" in output def test_verify_data(self): self._test_verify_data(RK_ENCRYPTION) diff --git a/src/borg/testsuite/archiver/delete_cmd.py b/src/borg/testsuite/archiver/delete_cmd.py index 6e7b7d976..b891a89a8 100644 --- a/src/borg/testsuite/archiver/delete_cmd.py +++ b/src/borg/testsuite/archiver/delete_cmd.py @@ -5,6 +5,7 @@ from ...manifest import Manifest from ...repository import Repository from . import ArchiverTestCaseBase, RemoteArchiverTestCaseBase, ArchiverTestCaseBinaryBase, RK_ENCRYPTION, BORG_EXES +from . import src_file class ArchiverTestCase(ArchiverTestCaseBase): @@ -48,7 +49,7 @@ def test_delete_force(self): manifest = Manifest.load(repository, Manifest.NO_OPERATION_CHECK) archive = Archive(manifest, "test") for item in archive.iter_items(): - if item.path.endswith("testsuite/archiver/__init__.py"): + if item.path.endswith(src_file): repository.delete(item.chunks[-1].id) break else: diff --git a/src/borg/testsuite/archiver/mount_cmds.py b/src/borg/testsuite/archiver/mount_cmds.py index 6b0ba1c5e..2858ffff2 100644 --- a/src/borg/testsuite/archiver/mount_cmds.py +++ b/src/borg/testsuite/archiver/mount_cmds.py @@ -14,14 +14,8 @@ from .. import changedir, no_selinux, same_ts_ns from .. import are_symlinks_supported, are_hardlinks_supported, are_fifos_supported from ..platform import fakeroot_detected -from . import ( - ArchiverTestCaseBase, - ArchiverTestCaseBinaryBase, - RemoteArchiverTestCaseBase, - RK_ENCRYPTION, - requires_hardlinks, - BORG_EXES, -) +from . import ArchiverTestCaseBase, ArchiverTestCaseBinaryBase, RemoteArchiverTestCaseBase, RK_ENCRYPTION, BORG_EXES +from . import src_file, requires_hardlinks class ArchiverTestCase(ArchiverTestCaseBase): @@ -205,7 +199,7 @@ def test_fuse_allow_damaged_files(self): archive, repository = self.open_archive("archive") with repository: for item in archive.iter_items(): - if item.path.endswith("testsuite/archiver/__init__.py"): + if item.path.endswith(src_file): repository.delete(item.chunks[-1].id) path = item.path # store full path for later break