1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-27 18:28:42 +00:00

split up keyfile, segments and overall testing in converter

This commit is contained in:
Antoine Beaupré 2015-10-01 00:32:34 -04:00
parent 1ba856d2b3
commit bcd94b96e0

View file

@ -12,7 +12,7 @@
pytestmark = pytest.mark.skipif(attic is None,
reason = 'cannot find an attic install')
from ..converter import AtticRepositoryConverter, NotImplementedException
from ..converter import AtticRepositoryConverter, NotImplementedException, AtticKeyfileKey
from ..helpers import get_keys_dir
from ..key import KeyfileKey
from ..repository import Repository, MAGIC
@ -20,10 +20,6 @@
class ConversionTestCase(BaseTestCase):
class MockArgs:
def __init__(self, path):
self.repository = attic.helpers.Location(path)
def open(self, path, repo_type = Repository, create=False):
return repo_type(os.path.join(path, 'repository'), create = create)
@ -37,6 +33,34 @@ def setUp(self):
self.attic_repo.put(('%-32d' % x).encode('ascii'), b'SOMEDATA')
self.attic_repo.close()
def tearDown(self):
shutil.rmtree(self.tmppath)
def check_repo(self, state = True):
if not state:
print("this will show an error, this is expected")
repository = self.open(self.tmppath)
assert repository.check() is state # can't check raises() because check() handles the error
repository.close()
def test_convert_segments(self):
# check should fail because of magic number
self.check_repo(False)
print("opening attic repository with borg and converting")
repo = self.open(self.tmppath, repo_type = AtticRepositoryConverter)
segments = [ filename for i, filename in repo.io.segment_iterator() ]
repo.close()
repo.convert_segments(segments, dryrun=False)
self.check_repo()
class EncryptedConversionTestCase(ConversionTestCase):
class MockArgs:
def __init__(self, path):
self.repository = attic.helpers.Location(path)
def setUp(self):
super().setUp()
# we use the repo dir for the created keyfile, because we do
# not want to clutter existing keyfiles
os.environ['ATTIC_KEYS_DIR'] = self.tmppath
@ -48,17 +72,18 @@ def setUp(self):
os.environ['ATTIC_PASSPHRASE'] = 'test'
self.key = attic.key.KeyfileKey.create(self.attic_repo, self.MockArgs(self.tmppath))
def tearDown(self):
shutil.rmtree(self.tmppath)
def test_keys(self):
repository = self.open(self.tmppath, repo_type = AtticRepositoryConverter)
keyfile = AtticKeyfileKey.find_key_file(repository)
AtticRepositoryConverter.convert_keyfiles(keyfile, dryrun=False)
def check_repo(self, state = True):
if not state:
print("this will show an error, this is expected")
self.repository = self.open(self.tmppath)
assert self.repository.check() is state # can't check raises() because check() handles the error
self.repository.close()
# check that the new keyfile is alright
keyfile = os.path.join(get_keys_dir(),
os.path.basename(self.key.path))
with open(keyfile, 'r') as f:
assert f.read().startswith(KeyfileKey.FILE_ID)
def test_convert(self):
def test_convert_all(self):
# check should fail because of magic number
self.check_repo(False)
print("opening attic repository with borg and converting")