Run end-to-end tests on developer machines with Docker Compose for approximate parity with continuous integration tests.
This commit is contained in:
parent
0cc711173a
commit
464ff2fe96
9 changed files with 106 additions and 25 deletions
35
.drone.yml
35
.drone.yml
|
@ -8,13 +8,18 @@ services:
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_PASSWORD: test
|
POSTGRES_PASSWORD: test
|
||||||
POSTGRES_DB: test
|
POSTGRES_DB: test
|
||||||
|
- name: mysql
|
||||||
|
image: mariadb:10.3
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: test
|
||||||
|
MYSQL_DATABASE: test
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: build
|
- name: build
|
||||||
image: python:3.5-alpine3.10
|
image: python:3.5-alpine3.10
|
||||||
pull: always
|
pull: always
|
||||||
commands:
|
commands:
|
||||||
- scripts/run-tests
|
- scripts/run-full-tests
|
||||||
---
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
name: python-3-6-alpine-3-10
|
name: python-3-6-alpine-3-10
|
||||||
|
@ -25,13 +30,18 @@ services:
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_PASSWORD: test
|
POSTGRES_PASSWORD: test
|
||||||
POSTGRES_DB: test
|
POSTGRES_DB: test
|
||||||
|
- name: mysql
|
||||||
|
image: mariadb:10.3
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: test
|
||||||
|
MYSQL_DATABASE: test
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: build
|
- name: build
|
||||||
image: python:3.6-alpine3.10
|
image: python:3.6-alpine3.10
|
||||||
pull: always
|
pull: always
|
||||||
commands:
|
commands:
|
||||||
- scripts/run-tests
|
- scripts/run-full-tests
|
||||||
---
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
name: python-3-7-alpine-3-10
|
name: python-3-7-alpine-3-10
|
||||||
|
@ -42,13 +52,18 @@ services:
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_PASSWORD: test
|
POSTGRES_PASSWORD: test
|
||||||
POSTGRES_DB: test
|
POSTGRES_DB: test
|
||||||
|
- name: mysql
|
||||||
|
image: mariadb:10.3
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: test
|
||||||
|
MYSQL_DATABASE: test
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: build
|
- name: build
|
||||||
image: python:3.7-alpine3.10
|
image: python:3.7-alpine3.10
|
||||||
pull: always
|
pull: always
|
||||||
commands:
|
commands:
|
||||||
- scripts/run-tests
|
- scripts/run-full-tests
|
||||||
---
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
name: python-3-7-alpine-3-7
|
name: python-3-7-alpine-3-7
|
||||||
|
@ -59,13 +74,18 @@ services:
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_PASSWORD: test
|
POSTGRES_PASSWORD: test
|
||||||
POSTGRES_DB: test
|
POSTGRES_DB: test
|
||||||
|
- name: mysql
|
||||||
|
image: mariadb:10.1
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: test
|
||||||
|
MYSQL_DATABASE: test
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: build
|
- name: build
|
||||||
image: python:3.7-alpine3.7
|
image: python:3.7-alpine3.7
|
||||||
pull: always
|
pull: always
|
||||||
commands:
|
commands:
|
||||||
- scripts/run-tests
|
- scripts/run-full-tests
|
||||||
---
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
name: python-3-8-alpine-3-10
|
name: python-3-8-alpine-3-10
|
||||||
|
@ -76,13 +96,18 @@ services:
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_PASSWORD: test
|
POSTGRES_PASSWORD: test
|
||||||
POSTGRES_DB: test
|
POSTGRES_DB: test
|
||||||
|
- name: mysql
|
||||||
|
image: mariadb:10.3
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: test
|
||||||
|
MYSQL_DATABASE: test
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: build
|
- name: build
|
||||||
image: python:3.8-alpine3.10
|
image: python:3.8-alpine3.10
|
||||||
pull: always
|
pull: always
|
||||||
commands:
|
commands:
|
||||||
- scripts/run-tests
|
- scripts/run-full-tests
|
||||||
---
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
name: documentation
|
name: documentation
|
||||||
|
|
5
NEWS
5
NEWS
|
@ -3,8 +3,9 @@
|
||||||
in location configuration section.
|
in location configuration section.
|
||||||
* #271: Support piping "borgmatic list" output to grep by logging certain log levels to console
|
* #271: Support piping "borgmatic list" output to grep by logging certain log levels to console
|
||||||
stdout and others to stderr.
|
stdout and others to stderr.
|
||||||
* Retain colored output when piping or redirecting output in an interactive terminal.
|
* Retain colored output when piping or redirecting in an interactive terminal.
|
||||||
* Add end-to-end tests for database dump and restore.
|
* Add end-to-end tests for database dump and restore. These are run on developer machines with
|
||||||
|
Docker Compose for approximate parity with continuous integration tests.
|
||||||
|
|
||||||
1.4.18
|
1.4.18
|
||||||
* Fix "--repository" flag to accept relative paths.
|
* Fix "--repository" flag to accept relative paths.
|
||||||
|
|
|
@ -75,14 +75,22 @@ tox -e isort
|
||||||
### End-to-end tests
|
### End-to-end tests
|
||||||
|
|
||||||
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 and supported databases for a few representative scenarios. These
|
||||||
because they're relatively slow and depend on Borg. If you would like to run
|
tests don't run by default when running `tox`, because they're relatively slow
|
||||||
them:
|
and depend on Docker containers for runtime dependencies. These tests tests do
|
||||||
|
run on the continuous integration (CI) server, and running them on your
|
||||||
|
developer machine is the closest thing to CI test parity.
|
||||||
|
|
||||||
|
If you would like to run the full test suite, first install Docker and [Docker
|
||||||
|
Compose](https://docs.docker.com/compose/install/). Then run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tox -e end-to-end
|
scripts/run-full-dev-tests
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Note that this scripts assumes you have permission to run Docker. If you
|
||||||
|
don't, then you may need to run with `sudo`.
|
||||||
|
|
||||||
## Code style
|
## Code style
|
||||||
|
|
||||||
Start with [PEP 8](https://www.python.org/dev/peps/pep-0008/). But then, apply
|
Start with [PEP 8](https://www.python.org/dev/peps/pep-0008/). But then, apply
|
||||||
|
|
13
scripts/run-full-dev-tests
Executable file
13
scripts/run-full-dev-tests
Executable file
|
@ -0,0 +1,13 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# This script is for running all tests, including end-to-end tests, on a developer machine. It sets
|
||||||
|
# up database containers to run tests against, runs the tests, and then tears down the containers.
|
||||||
|
#
|
||||||
|
# Run this script from the root directory of the borgmatic source.
|
||||||
|
#
|
||||||
|
# For more information, see:
|
||||||
|
# https://torsion.org/borgmatic/docs/how-to/develop-on-borgmatic/
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
docker-compose --file tests/end-to-end/docker-compose.yaml up --abort-on-container-exit
|
19
scripts/run-full-tests
Executable file
19
scripts/run-full-tests
Executable file
|
@ -0,0 +1,19 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# This script installs test dependencies and runs all tests, including end-to-end tests. It
|
||||||
|
# is designed to run inside a test container, and presumes that other test infrastructure like
|
||||||
|
# databases are already running. Therefore, on a developer machine, you should not run this script
|
||||||
|
# directly. Instead, run scripts/run-full-dev-tests
|
||||||
|
#
|
||||||
|
# For more information, see:
|
||||||
|
# https://torsion.org/borgmatic/docs/how-to/develop-on-borgmatic/
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
python -m pip install --upgrade pip==19.3.1
|
||||||
|
pip install tox==3.14.0
|
||||||
|
tox
|
||||||
|
apk add --no-cache borgbackup postgresql-client mariadb-client
|
||||||
|
working_directory="$PWD"
|
||||||
|
adduser --disabled-password tests
|
||||||
|
su - tests --command "cd $working_directory && tox --workdir /tmp -e end-to-end"
|
|
@ -1,13 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# This script is intended to be run from the continuous integration build
|
|
||||||
# server, and not on a developer machine. For that, see:
|
|
||||||
# https://torsion.org/borgmatic/docs/how-to/develop-on-borgmatic/
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
python -m pip install --upgrade pip==19.3.1
|
|
||||||
pip install tox==3.14.0
|
|
||||||
tox
|
|
||||||
apk add --no-cache borgbackup postgresql-client
|
|
||||||
tox -e end-to-end
|
|
23
tests/end-to-end/docker-compose.yaml
Normal file
23
tests/end-to-end/docker-compose.yaml
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
postgresql:
|
||||||
|
image: postgres:11.6-alpine
|
||||||
|
environment:
|
||||||
|
POSTGRES_PASSWORD: test
|
||||||
|
POSTGRES_DB: test
|
||||||
|
mysql:
|
||||||
|
image: mariadb:10.4
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: test
|
||||||
|
MYSQL_DATABASE: test
|
||||||
|
tests:
|
||||||
|
image: python:3.7-alpine3.10
|
||||||
|
volumes:
|
||||||
|
- "../..:/app"
|
||||||
|
tty: true
|
||||||
|
working_dir: /app
|
||||||
|
command:
|
||||||
|
- /app/scripts/run-full-tests
|
||||||
|
depends_on:
|
||||||
|
- postgresql
|
||||||
|
- mysql
|
|
@ -29,6 +29,11 @@ hooks:
|
||||||
hostname: postgresql
|
hostname: postgresql
|
||||||
username: postgres
|
username: postgres
|
||||||
password: test
|
password: test
|
||||||
|
mysql_databases:
|
||||||
|
- name: test
|
||||||
|
hostname: mysql
|
||||||
|
username: root
|
||||||
|
password: test
|
||||||
'''.format(
|
'''.format(
|
||||||
config_path, repository_path, borgmatic_source_directory
|
config_path, repository_path, borgmatic_source_directory
|
||||||
)
|
)
|
||||||
|
|
2
tox.ini
2
tox.ini
|
@ -11,7 +11,7 @@ whitelist_externals =
|
||||||
find
|
find
|
||||||
sh
|
sh
|
||||||
commands_pre =
|
commands_pre =
|
||||||
find {toxinidir} -type f -not -path '{toxinidir}/.tox/*' -path '*/__pycache__/*' -name '*.py[c|o]' -delete
|
find {envdir} -type f -not -path '*/__pycache__/*' -name '*.py[c|o]' -delete
|
||||||
commands =
|
commands =
|
||||||
pytest {posargs}
|
pytest {posargs}
|
||||||
py36,py37,py38: black --check .
|
py36,py37,py38: black --check .
|
||||||
|
|
Loading…
Reference in a new issue