Tests

Prerequisites

You should have installed the following tools on your machine:

  1. Python

  2. Pip

  3. Tox (via pip)

  4. Vagrant, Docker and/or podman (depending on the role you are testing: check molecule.yml)

  5. Virtualbox/Libvirt or Parallels (dependending on your OS)

Running tests

Running Ansible test is fairly easy if you’ve installed the prerequisites.

First, generate all the python requirement files tox -e pipdep command.

Then, you can run the tests using tox -e test-exec — --scenario-name <your-scenario> the scenario name being the name of the virtualization technology you use according to the molecule folder.

You can also create, converge, lint, …​ As you would do using ansible molecule framework.

Finally, there’s a monorepo option on high level roles (the ones that requires other roles to be installed) that will allow you to test the role in a monorepo context (it will use all the roles that are on the same path than the curren tone instead of their released version.

Tip
Be sure to write your test before implementing so that you can see it failing, so to ensure that you are writing your test the good way !

Test pipelines

We are using act in order to test our pipeline before pushing to github (lint, docker-compatible roles) or travis-ci (molecule vagrant roles).

On any repository, you can execute act list to see all the available actions and act <action> to trigger it. You can always update the container used to trigger the tests updating the .actrc file