From 3ce5533103ffcc6f1556d555c22c444963abcb33 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Wed, 3 Oct 2018 22:36:25 -0700 Subject: [PATCH] Make end-to-end test clean up after itself, and drop unnecessary use of Docker for it. --- .drone.yml | 2 ++ README.md | 7 ++-- tests/end-to-end/test_borgmatic.py | 54 +++++++++++++++++++----------- tox.ini | 7 ++-- 4 files changed, 40 insertions(+), 30 deletions(-) diff --git a/.drone.yml b/.drone.yml index 6815e4a..6fd6bdb 100644 --- a/.drone.yml +++ b/.drone.yml @@ -5,3 +5,5 @@ pipeline: commands: - pip install tox - tox + - apk add --no-cache borgbackup + - tox -e end-to-end diff --git a/README.md b/README.md index a5c8fd4..0db9962 100644 --- a/README.md +++ b/README.md @@ -457,16 +457,13 @@ tox -e black borgmatic additionally includes some end-to-end tests that integration test with Borg for a few representative scenarios. These tests don't run by default -because they're slow and require Docker. If you would like to run them, first -install Docker, and make sure that it's executable by the current user. Then: +because they're relatively slow and depend on Borg. If you would like to run +them: ```bash tox -e end-to-end ``` -That builds a test container with your local borgmatic source, and runs -end-to-end tests within it. - ## Troubleshooting ### Broken pipe with remote repository diff --git a/tests/end-to-end/test_borgmatic.py b/tests/end-to-end/test_borgmatic.py index a677b52..ca3f2ad 100644 --- a/tests/end-to-end/test_borgmatic.py +++ b/tests/end-to-end/test_borgmatic.py @@ -1,39 +1,53 @@ import json import os +import shutil import subprocess import sys +import tempfile -def generate_configuration(): - subprocess.check_call('generate-borgmatic-config --destination test.yaml'.split(' ')) +def generate_configuration(config_path, repository_path): + ''' + Generate borgmatic configuration into a file at the config path, and update the defaults so as + to work for testing (including injecting the given repository path). + ''' + subprocess.check_call(f'generate-borgmatic-config --destination {config_path}'.split(' ')) config = ( - open('test.yaml') + open(config_path) .read() - .replace('user@backupserver:sourcehostname.borg', 'test.borg') - .replace('- /etc', '- /app') + .replace('user@backupserver:sourcehostname.borg', repository_path) + .replace('- /home', f'- {config_path}') + .replace('- /etc', '') .replace('- /var/log/syslog*', '') ) - config_file = open('test.yaml', 'w') + config_file = open(config_path, 'w') config_file.write(config) config_file.close() def test_borgmatic_command(): # Create a Borg repository. - subprocess.check_call( - 'borg init --encryption repokey test.borg'.split(' '), - env={'BORG_PASSPHRASE': '', **os.environ}, - ) + temporary_directory = tempfile.mkdtemp() + repository_path = os.path.join(temporary_directory, 'test.borg') - # Generate borgmatic configuration, and update the defaults so as to work for this test. - generate_configuration() + try: + subprocess.check_call( + f'borg init --encryption repokey {repository_path}'.split(' '), + env={'BORG_PASSPHRASE': '', **os.environ}, + ) - # Run borgmatic to generate a backup archive, and then list it to make sure it exists. - subprocess.check_call('borgmatic --config test.yaml'.split(' ')) - output = subprocess.check_output( - 'borgmatic --config test.yaml --list --json'.split(' '), encoding=sys.stdout.encoding - ) - parsed_output = json.loads(output) + config_path = os.path.join(temporary_directory, 'test.yaml') + generate_configuration(config_path, repository_path) - assert len(parsed_output) == 1 - assert len(parsed_output[0]['archives']) == 1 + # Run borgmatic to generate a backup archive, and then list it to make sure it exists. + subprocess.check_call(f'borgmatic --config {config_path}'.split(' ')) + output = subprocess.check_output( + f'borgmatic --config {config_path} --list --json'.split(' '), + encoding=sys.stdout.encoding, + ) + parsed_output = json.loads(output) + + assert len(parsed_output) == 1 + assert len(parsed_output[0]['archives']) == 1 + finally: + shutil.rmtree(temporary_directory) diff --git a/tox.ini b/tox.ini index 4444d45..6774f58 100644 --- a/tox.ini +++ b/tox.ini @@ -17,12 +17,9 @@ commands = black --skip-string-normalization --line-length 100 . [testenv:end-to-end] -whitelist_externals = docker -skip_install = true -deps = +deps = -rtest_requirements.txt commands = - docker build --file tests/end-to-end/Dockerfile --tag borgmatic-test . - docker run --rm borgmatic-test py.test tests/end-to-end [] + py.test tests/end-to-end [] [flake8] ignore = E501,W503