Make end-to-end test clean up after itself, and drop unnecessary use of Docker for it.
This commit is contained in:
parent
4a1ee8c911
commit
3ce5533103
4 changed files with 40 additions and 30 deletions
|
@ -5,3 +5,5 @@ pipeline:
|
|||
commands:
|
||||
- pip install tox
|
||||
- tox
|
||||
- apk add --no-cache borgbackup
|
||||
- tox -e end-to-end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
temporary_directory = tempfile.mkdtemp()
|
||||
repository_path = os.path.join(temporary_directory, 'test.borg')
|
||||
|
||||
try:
|
||||
subprocess.check_call(
|
||||
'borg init --encryption repokey test.borg'.split(' '),
|
||||
f'borg init --encryption repokey {repository_path}'.split(' '),
|
||||
env={'BORG_PASSPHRASE': '', **os.environ},
|
||||
)
|
||||
|
||||
# Generate borgmatic configuration, and update the defaults so as to work for this test.
|
||||
generate_configuration()
|
||||
config_path = os.path.join(temporary_directory, 'test.yaml')
|
||||
generate_configuration(config_path, repository_path)
|
||||
|
||||
# Run borgmatic to generate a backup archive, and then list it to make sure it exists.
|
||||
subprocess.check_call('borgmatic --config test.yaml'.split(' '))
|
||||
subprocess.check_call(f'borgmatic --config {config_path}'.split(' '))
|
||||
output = subprocess.check_output(
|
||||
'borgmatic --config test.yaml --list --json'.split(' '), encoding=sys.stdout.encoding
|
||||
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)
|
||||
|
|
7
tox.ini
7
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
|
||||
|
|
Loading…
Reference in a new issue