Quellcode durchsuchen

Add archive extract to end-to-end test.

Dan Helfman vor 6 Jahren
Ursprung
Commit
2b3b8eab71
2 geänderte Dateien mit 19 neuen und 2 gelöschten Zeilen
  1. 1 1
      borgmatic/commands/borgmatic.py
  2. 18 1
      tests/end-to-end/test_borgmatic.py

+ 1 - 1
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,

+ 18 - 1
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']
+
+        # 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()
 
-        # Also exercise the info flag.
+        # 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)