Skip to content

Commit

Permalink
Add an additional end-to-end database test.
Browse files Browse the repository at this point in the history
  • Loading branch information
witten committed May 15, 2020
1 parent de478f6 commit 048a9eb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import find_packages, setup

VERSION = '1.5.4.dev0'
VERSION = '1.5.4'


setup(
Expand Down
2 changes: 1 addition & 1 deletion tests/end-to-end/test_borgmatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 38 additions & 1 deletion tests/end-to-end/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import sys
import tempfile

import pytest


def write_configuration(config_path, repository_path, borgmatic_source_directory):
'''
Expand Down Expand Up @@ -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.
Expand All @@ -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)

0 comments on commit 048a9eb

Please sign in to comment.