tests: use a smaller dir for src_dir, fixes #7518

also: introduce src_file, which is a file in src_dir.
This commit is contained in:
Thomas Waldmann 2023-04-15 16:46:23 +02:00
parent 9263705de7
commit 4505c90920
No known key found for this signature in database
GPG Key ID: 243ACFA951F78E01
4 changed files with 15 additions and 17 deletions

View File

@ -33,7 +33,9 @@ from ..platform import is_win32
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")

View File

@ -10,6 +10,7 @@ from ...helpers import msgpack
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 @@ class ArchiverCheckTestCase(ArchiverTestCaseBase):
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 @@ class ArchiverCheckTestCase(ArchiverTestCaseBase):
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 @@ class ArchiverCheckTestCase(ArchiverTestCaseBase):
# 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 @@ class ArchiverCheckTestCase(ArchiverTestCaseBase):
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 @@ class ArchiverCheckTestCase(ArchiverTestCaseBase):
# 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)

View File

@ -5,6 +5,7 @@ from ...constants import * # NOQA
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 @@ class ArchiverTestCase(ArchiverTestCaseBase):
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:

View File

@ -14,14 +14,8 @@ from .. import has_lchflags, llfuse
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 @@ class ArchiverTestCase(ArchiverTestCaseBase):
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