mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-29 03:06:12 +00:00
split up keyfile, segments and overall testing in converter
This commit is contained in:
parent
1ba856d2b3
commit
bcd94b96e0
1 changed files with 39 additions and 14 deletions
|
@ -12,7 +12,7 @@
|
||||||
pytestmark = pytest.mark.skipif(attic is None,
|
pytestmark = pytest.mark.skipif(attic is None,
|
||||||
reason = 'cannot find an attic install')
|
reason = 'cannot find an attic install')
|
||||||
|
|
||||||
from ..converter import AtticRepositoryConverter, NotImplementedException
|
from ..converter import AtticRepositoryConverter, NotImplementedException, AtticKeyfileKey
|
||||||
from ..helpers import get_keys_dir
|
from ..helpers import get_keys_dir
|
||||||
from ..key import KeyfileKey
|
from ..key import KeyfileKey
|
||||||
from ..repository import Repository, MAGIC
|
from ..repository import Repository, MAGIC
|
||||||
|
@ -20,10 +20,6 @@
|
||||||
|
|
||||||
class ConversionTestCase(BaseTestCase):
|
class ConversionTestCase(BaseTestCase):
|
||||||
|
|
||||||
class MockArgs:
|
|
||||||
def __init__(self, path):
|
|
||||||
self.repository = attic.helpers.Location(path)
|
|
||||||
|
|
||||||
def open(self, path, repo_type = Repository, create=False):
|
def open(self, path, repo_type = Repository, create=False):
|
||||||
return repo_type(os.path.join(path, 'repository'), create = create)
|
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.put(('%-32d' % x).encode('ascii'), b'SOMEDATA')
|
||||||
self.attic_repo.close()
|
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
|
# we use the repo dir for the created keyfile, because we do
|
||||||
# not want to clutter existing keyfiles
|
# not want to clutter existing keyfiles
|
||||||
os.environ['ATTIC_KEYS_DIR'] = self.tmppath
|
os.environ['ATTIC_KEYS_DIR'] = self.tmppath
|
||||||
|
@ -48,17 +72,18 @@ def setUp(self):
|
||||||
os.environ['ATTIC_PASSPHRASE'] = 'test'
|
os.environ['ATTIC_PASSPHRASE'] = 'test'
|
||||||
self.key = attic.key.KeyfileKey.create(self.attic_repo, self.MockArgs(self.tmppath))
|
self.key = attic.key.KeyfileKey.create(self.attic_repo, self.MockArgs(self.tmppath))
|
||||||
|
|
||||||
def tearDown(self):
|
def test_keys(self):
|
||||||
shutil.rmtree(self.tmppath)
|
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):
|
# check that the new keyfile is alright
|
||||||
if not state:
|
keyfile = os.path.join(get_keys_dir(),
|
||||||
print("this will show an error, this is expected")
|
os.path.basename(self.key.path))
|
||||||
self.repository = self.open(self.tmppath)
|
with open(keyfile, 'r') as f:
|
||||||
assert self.repository.check() is state # can't check raises() because check() handles the error
|
assert f.read().startswith(KeyfileKey.FILE_ID)
|
||||||
self.repository.close()
|
|
||||||
|
|
||||||
def test_convert(self):
|
def test_convert_all(self):
|
||||||
# check should fail because of magic number
|
# check should fail because of magic number
|
||||||
self.check_repo(False)
|
self.check_repo(False)
|
||||||
print("opening attic repository with borg and converting")
|
print("opening attic repository with borg and converting")
|
||||||
|
|
Loading…
Reference in a new issue