Add archive extract to end-to-end test.

This commit is contained in:
Dan Helfman 2019-02-18 13:47:18 -08:00
parent aa7c7651e5
commit 2b3b8eab71
2 changed files with 19 additions and 2 deletions

View File

@ -347,7 +347,7 @@ def _run_commands_on_repository(
repository, storage, consistency, local_path=local_path, remote_path=remote_path
)
if args.extract:
if repository == args.repository:
if args.repository is None or repository == args.repository:
logger.info('{}: Extracting archive {}'.format(repository, args.archive))
borg_extract.extract_archive(
args.dry_run,

View File

@ -33,6 +33,11 @@ def test_borgmatic_command():
# Create a Borg repository.
temporary_directory = tempfile.mkdtemp()
repository_path = os.path.join(temporary_directory, 'test.borg')
extract_path = os.path.join(temporary_directory, 'extract')
original_working_directory = os.getcwd()
os.mkdir(extract_path)
os.chdir(extract_path)
try:
config_path = os.path.join(temporary_directory, 'test.yaml')
@ -51,8 +56,19 @@ def test_borgmatic_command():
assert len(parsed_output) == 1
assert len(parsed_output[0]['archives']) == 1
archive_name = parsed_output[0]['archives'][0]['archive']
# Also exercise the info flag.
# Extract the created archive into the current (temporary) directory, and confirm that the
# extracted file looks right.
output = subprocess.check_output(
'borgmatic --config {} --extract --archive {}'.format(config_path, archive_name).split(
' '
)
).decode(sys.stdout.encoding)
extracted_config_path = os.path.join(extract_path, config_path)
assert open(extracted_config_path).read() == open(config_path).read()
# Exercise the info flag.
output = subprocess.check_output(
'borgmatic --config {} --info --json'.format(config_path).split(' ')
).decode(sys.stdout.encoding)
@ -61,4 +77,5 @@ def test_borgmatic_command():
assert len(parsed_output) == 1
assert 'repository' in parsed_output[0]
finally:
os.chdir(original_working_directory)
shutil.rmtree(temporary_directory)