Make end-to-end test clean up after itself, and drop unnecessary use of Docker for it.
All checks were successful
the build was successful
All checks were successful
the build was successful
This commit is contained in:
parent
4a1ee8c911
commit
3ce5533103
|
@ -5,3 +5,5 @@ pipeline:
|
||||||
commands:
|
commands:
|
||||||
- pip install tox
|
- pip install tox
|
||||||
- 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
|
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
|
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
|
because they're relatively slow and depend on Borg. If you would like to run
|
||||||
install Docker, and make sure that it's executable by the current user. Then:
|
them:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tox -e end-to-end
|
tox -e end-to-end
|
||||||
```
|
```
|
||||||
|
|
||||||
That builds a test container with your local borgmatic source, and runs
|
|
||||||
end-to-end tests within it.
|
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
### Broken pipe with remote repository
|
### Broken pipe with remote repository
|
||||||
|
|
|
@ -1,39 +1,53 @@
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
|
||||||
def generate_configuration():
|
def generate_configuration(config_path, repository_path):
|
||||||
subprocess.check_call('generate-borgmatic-config --destination test.yaml'.split(' '))
|
'''
|
||||||
|
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 = (
|
config = (
|
||||||
open('test.yaml')
|
open(config_path)
|
||||||
.read()
|
.read()
|
||||||
.replace('user@backupserver:sourcehostname.borg', 'test.borg')
|
.replace('user@backupserver:sourcehostname.borg', repository_path)
|
||||||
.replace('- /etc', '- /app')
|
.replace('- /home', f'- {config_path}')
|
||||||
|
.replace('- /etc', '')
|
||||||
.replace('- /var/log/syslog*', '')
|
.replace('- /var/log/syslog*', '')
|
||||||
)
|
)
|
||||||
config_file = open('test.yaml', 'w')
|
config_file = open(config_path, 'w')
|
||||||
config_file.write(config)
|
config_file.write(config)
|
||||||
config_file.close()
|
config_file.close()
|
||||||
|
|
||||||
|
|
||||||
def test_borgmatic_command():
|
def test_borgmatic_command():
|
||||||
# Create a Borg repository.
|
# Create a Borg repository.
|
||||||
subprocess.check_call(
|
temporary_directory = tempfile.mkdtemp()
|
||||||
'borg init --encryption repokey test.borg'.split(' '),
|
repository_path = os.path.join(temporary_directory, 'test.borg')
|
||||||
env={'BORG_PASSPHRASE': '', **os.environ},
|
|
||||||
)
|
|
||||||
|
|
||||||
# Generate borgmatic configuration, and update the defaults so as to work for this test.
|
try:
|
||||||
generate_configuration()
|
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.
|
config_path = os.path.join(temporary_directory, 'test.yaml')
|
||||||
subprocess.check_call('borgmatic --config test.yaml'.split(' '))
|
generate_configuration(config_path, repository_path)
|
||||||
output = subprocess.check_output(
|
|
||||||
'borgmatic --config test.yaml --list --json'.split(' '), encoding=sys.stdout.encoding
|
|
||||||
)
|
|
||||||
parsed_output = json.loads(output)
|
|
||||||
|
|
||||||
assert len(parsed_output) == 1
|
# Run borgmatic to generate a backup archive, and then list it to make sure it exists.
|
||||||
assert len(parsed_output[0]['archives']) == 1
|
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)
|
||||||
|
|
7
tox.ini
7
tox.ini
|
@ -17,12 +17,9 @@ commands =
|
||||||
black --skip-string-normalization --line-length 100 .
|
black --skip-string-normalization --line-length 100 .
|
||||||
|
|
||||||
[testenv:end-to-end]
|
[testenv:end-to-end]
|
||||||
whitelist_externals = docker
|
deps = -rtest_requirements.txt
|
||||||
skip_install = true
|
|
||||||
deps =
|
|
||||||
commands =
|
commands =
|
||||||
docker build --file tests/end-to-end/Dockerfile --tag borgmatic-test .
|
py.test tests/end-to-end []
|
||||||
docker run --rm borgmatic-test py.test tests/end-to-end []
|
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
ignore = E501,W503
|
ignore = E501,W503
|
||||||
|
|
Loading…
Reference in New Issue
Block a user