Răsfoiți Sursa

Add an additional end-to-end database test.

Dan Helfman 5 ani în urmă
părinte
comite
048a9ebb52
4 a modificat fișierele cu 41 adăugiri și 4 ștergeri
  1. 1 1
      NEWS
  2. 1 1
      setup.py
  3. 1 1
      tests/end-to-end/test_borgmatic.py
  4. 38 1
      tests/end-to-end/test_database.py

+ 1 - 1
NEWS

@@ -1,4 +1,4 @@
-1.5.4.dev0
+1.5.4
  * #310: Fix legitimate database dump command errors (exit code 1) not being treated as errors by
    borgmatic.
  * For database dumps, replace the named pipe on every borgmatic run. This prevent hangs on stale

+ 1 - 1
setup.py

@@ -1,6 +1,6 @@
 from setuptools import find_packages, setup
 
-VERSION = '1.5.4.dev0'
+VERSION = '1.5.4'
 
 
 setup(

+ 1 - 1
tests/end-to-end/test_borgmatic.py

@@ -68,7 +68,7 @@ def test_borgmatic_command():
         extracted_config_path = os.path.join(extract_path, config_path)
         assert open(extracted_config_path).read() == open(config_path).read()
 
-        # Exercise the info flag.
+        # Exercise the info action.
         output = subprocess.check_output(
             'borgmatic --config {} info --json'.format(config_path).split(' ')
         ).decode(sys.stdout.encoding)

+ 38 - 1
tests/end-to-end/test_database.py

@@ -5,6 +5,8 @@ import subprocess
 import sys
 import tempfile
 
+import pytest
+
 
 def write_configuration(config_path, repository_path, borgmatic_source_directory):
     '''
@@ -67,7 +69,7 @@ def test_database_dump_and_restore():
             'borgmatic -v 2 --config {} init --encryption repokey'.format(config_path).split(' ')
         )
 
-        # Run borgmatic to generate a backup archive including a database dump
+        # Run borgmatic to generate a backup archive including a database dump.
         subprocess.check_call('borgmatic create --config {} -v 2'.format(config_path).split(' '))
 
         # Get the created archive name.
@@ -89,3 +91,38 @@ def test_database_dump_and_restore():
     finally:
         os.chdir(original_working_directory)
         shutil.rmtree(temporary_directory)
+
+
+def test_database_dump_with_error_causes_borgmatic_to_exit():
+    # Create a Borg repository.
+    temporary_directory = tempfile.mkdtemp()
+    repository_path = os.path.join(temporary_directory, 'test.borg')
+    borgmatic_source_directory = os.path.join(temporary_directory, '.borgmatic')
+
+    original_working_directory = os.getcwd()
+
+    try:
+        config_path = os.path.join(temporary_directory, 'test.yaml')
+        write_configuration(config_path, repository_path, borgmatic_source_directory)
+
+        subprocess.check_call(
+            'borgmatic -v 2 --config {} init --encryption repokey'.format(config_path).split(' ')
+        )
+
+        # Run borgmatic with a config override such that the database dump fails.
+        with pytest.raises(subprocess.CalledProcessError):
+            subprocess.check_call(
+                [
+                    'borgmatic',
+                    'create',
+                    '--config',
+                    config_path,
+                    '-v',
+                    '2',
+                    '--override',
+                    "hooks.postgresql_databases=[{'name': 'nope'}]",
+                ]
+            )
+    finally:
+        os.chdir(original_working_directory)
+        shutil.rmtree(temporary_directory)