From 048a9ebb52f81ffd328a972c61d0e44a98743f74 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Fri, 15 May 2020 10:12:49 -0700 Subject: [PATCH] Add an additional end-to-end database test. --- NEWS | 2 +- setup.py | 2 +- tests/end-to-end/test_borgmatic.py | 2 +- tests/end-to-end/test_database.py | 39 +++++++++++++++++++++++++++++- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 379d8c43..2a7891cd 100644 --- a/NEWS +++ b/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 diff --git a/setup.py b/setup.py index 06bb76e7..474b0189 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.5.4.dev0' +VERSION = '1.5.4' setup( diff --git a/tests/end-to-end/test_borgmatic.py b/tests/end-to-end/test_borgmatic.py index 0bfe7b7b..36c242a4 100644 --- a/tests/end-to-end/test_borgmatic.py +++ b/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) diff --git a/tests/end-to-end/test_database.py b/tests/end-to-end/test_database.py index 03762a42..ade5b2ed 100644 --- a/tests/end-to-end/test_database.py +++ b/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)