From 2b3b8eab713d1be696d5a19c4c9660f1e36bf15b Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 18 Feb 2019 13:47:18 -0800 Subject: [PATCH] Add archive extract to end-to-end test. --- borgmatic/commands/borgmatic.py | 2 +- tests/end-to-end/test_borgmatic.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index 0b5b681..31f18e1 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -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, diff --git a/tests/end-to-end/test_borgmatic.py b/tests/end-to-end/test_borgmatic.py index 76802d3..620e67a 100644 --- a/tests/end-to-end/test_borgmatic.py +++ b/tests/end-to-end/test_borgmatic.py @@ -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)