Add an end-to-end automated test that actually integrates with Borg.
This commit is contained in:
parent
a125df991b
commit
0b164973e0
6 changed files with 87 additions and 8 deletions
1
NEWS
1
NEWS
|
@ -1,5 +1,6 @@
|
||||||
1.2.7.dev0
|
1.2.7.dev0
|
||||||
* Use Black code formatter and Flake8 code checker as part of running automated tests.
|
* Use Black code formatter and Flake8 code checker as part of running automated tests.
|
||||||
|
* Add an end-to-end automated test that actually integrates with Borg.
|
||||||
|
|
||||||
1.2.6
|
1.2.6
|
||||||
* Fix generated configuration to also include a "keep_daily" value so pruning works out of the
|
* Fix generated configuration to also include a "keep_daily" value so pruning works out of the
|
||||||
|
|
13
README.md
13
README.md
|
@ -453,6 +453,19 @@ following:
|
||||||
tox -e black
|
tox -e black
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### End-to-end tests
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
```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
|
## Troubleshooting
|
||||||
|
|
||||||
|
|
17
tests/end-to-end/Dockerfile
Normal file
17
tests/end-to-end/Dockerfile
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
FROM b3vis/borgmatic
|
||||||
|
|
||||||
|
# Starting from an existing borgmatic image, install the local source on top of
|
||||||
|
# it so that we can test any local changes.
|
||||||
|
RUN adduser -h /home -D app
|
||||||
|
COPY test_requirements.txt /app/
|
||||||
|
RUN pip3 install --upgrade --requirement /app/test_requirements.txt
|
||||||
|
COPY . /app
|
||||||
|
RUN rm -fr /app/.tox /app/.git \
|
||||||
|
&& pip3 install --upgrade /app \
|
||||||
|
&& chown -R app /app
|
||||||
|
|
||||||
|
USER app
|
||||||
|
WORKDIR /app
|
||||||
|
ENV BORG_CACHE_DIR "/app/.cache/borg"
|
||||||
|
|
||||||
|
CMD ["py.test"]
|
0
tests/end-to-end/__init__.py
Normal file
0
tests/end-to-end/__init__.py
Normal file
39
tests/end-to-end/test_borgmatic.py
Normal file
39
tests/end-to-end/test_borgmatic.py
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def generate_configuration():
|
||||||
|
subprocess.check_call('generate-borgmatic-config --destination test.yaml'.split(' '))
|
||||||
|
config = (
|
||||||
|
open('test.yaml')
|
||||||
|
.read()
|
||||||
|
.replace('user@backupserver:sourcehostname.borg', 'test.borg')
|
||||||
|
.replace('- /etc', '- /app')
|
||||||
|
.replace('- /var/log/syslog*', '')
|
||||||
|
)
|
||||||
|
config_file = open('test.yaml', '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},
|
||||||
|
)
|
||||||
|
|
||||||
|
# Generate borgmatic configuration, and update the defaults so as to work for this test.
|
||||||
|
generate_configuration()
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
assert len(parsed_output) == 1
|
||||||
|
assert len(parsed_output[0]['archives']) == 1
|
25
tox.ini
25
tox.ini
|
@ -1,20 +1,29 @@
|
||||||
[tox]
|
[tox]
|
||||||
envlist=py3
|
envlist = py3
|
||||||
skipsdist=True
|
skipsdist = True
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
usedevelop=True
|
usedevelop = True
|
||||||
deps=-rtest_requirements.txt
|
deps = -rtest_requirements.txt
|
||||||
commands =
|
commands =
|
||||||
py.test --cov-report term-missing:skip-covered --cov=borgmatic tests []
|
py.test --cov-report term-missing:skip-covered --cov=borgmatic --ignore=tests/end-to-end \
|
||||||
|
tests []
|
||||||
black --skip-string-normalization --line-length 100 --check .
|
black --skip-string-normalization --line-length 100 --check .
|
||||||
flake8 .
|
flake8 .
|
||||||
|
|
||||||
[testenv:black]
|
[testenv:black]
|
||||||
basepython=python3.7
|
basepython = python3.7
|
||||||
commands =
|
commands =
|
||||||
black --skip-string-normalization --line-length 100 .
|
black --skip-string-normalization --line-length 100 .
|
||||||
|
|
||||||
|
[testenv:end-to-end]
|
||||||
|
whitelist_externals = docker
|
||||||
|
skip_install = true
|
||||||
|
deps =
|
||||||
|
commands =
|
||||||
|
docker build --file tests/end-to-end/Dockerfile --tag borgmatic-test .
|
||||||
|
docker run --rm borgmatic-test py.test tests/end-to-end []
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
ignore=E501,W503
|
ignore = E501,W503
|
||||||
exclude=*.*/*
|
exclude = *.*/*
|
||||||
|
|
Loading…
Reference in a new issue