Testing

Project validation is done using Travis CI.

The actual role and playbook testing is performed by the project developers using GitLab CI in a locally hosted development environment.

Travis CI

You can easily run the Travis CI suite on your local fork, by running make test.

The Makefile includes linting with several different tools, building the documentation, and testing the project on a docker image.

Software dependencies

sudo apt install build-essential git graphviz shellcheck \
                 python3-sphinx python3-sphinx-rtd-theme

pip install -U pycodestyle pytest pytest-cov yamllint ansible-lint reuse

If you intend on running make docker, you also need Docker and a user able to run docker containers.

Installing Docker Community Edition on Debian involves adding their apt repository that corresponds to your distro, as described in the Docker CE Debian installation instructions.

You may also want to check out Docker CE post-installation steps for linux. For our purposes, all you need is to add your user to the docker group:

sudo usermod -aG docker <username>
# log out or reboot for this to take effect.

make test

Runs all tests. This runs on automatically on contributions on github.

make test-unit

Runs the unit tests for the debops Python package using pytest, together with a coverage report. The tests live in src/tests/unit/; each module of the package has a matching test_*.py file. External tools are replaced with test doubles, so the suite runs the same way on any machine.

make test-integration

Runs the integration tests from src/tests/integration/, which drive the real debops command line in temporary directories: project initialization, command dispatch and secret management. Tests which need optional tools such as ansible-inventory, git-crypt or encfs are skipped when the tools are not installed.

make test-coverage

Runs the unit and integration tests together and prints a combined coverage report. Use this to see the real coverage of the modules which the integration tests exercise, for example the project directory management; the unit-only report of make test-unit understates them.

make help

Displays all make targets, along with a useful description. :)

make docker

The test code in make test checks if Docker is available, and if not, this particular test is successfully skipped.

Verifies the Dockerfile and checks if Ansible and DebOps run fine inside of a Docker container.

make docs

While working with documentation, it can be useful to only run this bit.

The resulting html files will be in docs/_build/html/.

Mutation testing

Code coverage tells you which lines the test suite executes. Mutation testing tells you which lines the test suite actually validates. The mutmut tool generates small mutations of the src/debops/ sources — flipped comparisons, changed constants, removed statements — and runs the tests against each mutant. A mutant that survives means the suite passes with broken code: a gap in the assertions.

Run it locally with:

mutmut run

A full pass over the package generates around 11k mutants and takes a few minutes on a typical workstation. Review the results with mutmut results, and inspect an individual mutant with mutmut show <mutant-id>. The configuration lives in the [tool.mutmut] section of pyproject.toml.

A few things to keep in mind when reading the results:

  • Integration tests are excluded from the mutation loop. They drive the real debops command line in subprocesses, which cannot see the mutated code, so they would always pass regardless of the mutations.

  • Surviving mutants in code that only builds git or ansible-playbook command lines are expected. The interesting findings are in the logic modules: configuration handling, inventory parsing, version comparison.

  • The goal is not a 100% mutation score. Triage the survivors, fix the assertion gaps that matter, and accept the rest.

The mutants/ directory created during a run is a scratch copy of the project used to apply the mutations. It is ignored by Git and can be removed at any time.