Skip to content

Testing your changes

Andrew Klychkov edited this page Oct 19, 2020 · 17 revisions

For what we must have tests whenever possible

Tests are extremely important for stability of stuff in this repository.

In order to make sure your changes will not break anything / you fixed a bug / nobody can break the added functionality later:

  • cover the case as completely as possible

  • be sure your tests cover check_mode if applicable

  • be sure that functionality that can be affected by your changes is also covered, if not, cover it

  • fixing a bug, write tests before changing related code, run them to see the bug exists. Then fix the bug, run the tests again to see the bug does not appear any more

Useful references

Prerequisites

We are assuming that you:

  • downloaded community.mysql repository

  • created directories ansible_collections/general in your home directory

  • moved the repository mv community.mysql ansible_collections/general/mysql

  • made some changes

  • added integration tests that cover your changes to one of the files in the tests/integration/targets/test_mysql_* directory (or you just want to run existing tests in order to check that your changes do not break currently covered code)

  • if you do not know how to add tests for your case, create a pull request and ask other contributors there for help

Prepare testing environment

  1. Install docker daemon on your system, run it.

  2. Download ansible-base repository.

  3. Go to the ansible-base repository root directory.

  4. Run source hacking/env-setup.

Note: Steps 2-4 are needed if you want to use devel version of ansible-test utility.

Run integration tests

  1. Go to the community.mysql repository root directory.

  2. Run (change test_mysql_query to an appropriate test directory name):

    ansible-test integration test_mysql_query --docker --docker-no-pull -vvv > /tmp/test.log

    Be sure you use default docker container, use the --docker default or just --docker command-line option.

  3. If something goes wrong, you can check the output stored in /tmp/test.log.

Run sanity tests

To run sanity tests:

  1. Be sure you ran source hacking/env-setup as described above.

  2. Run (change mysql_query.py to an appropriate file path):

    ansible-test sanity plugins/modules/mysql_query.py --docker --docker-no-pull

    Be sure you use default docker container, use the --docker default or just --docker command-line option.

When there are issues with local testing

  • You can just create a pull request in this repository and all sanity and integration tests (including yours) will run here automatically and you'll get a detailed report

  • Create a pull request and ask other contributors to help with running tests locally there.

Clone this wiki locally