Sanity Tests
Topics
Sanity tests are made up of scripts and tools used to perform static code analysis. The primary purpose of these tests is to enforce Ansible coding standards and requirements.
Tests are run with ansible-test sanity. All available tests are run unless the --test option is used.
Set up your environment
Install ansible-core<installation_guide>that provides theansible-testtool.
- If you want to run checks available in the development version of
ansible-core,install it from source code<from_source>.
- Run
source hacking/env-setupfrom its source code directory in the same terminal session you run your tests.
- Install
podmanordockerto avoid installing all the dependencies on your system. - If you test files in a collection:
- Ensure you have your collection installed in the following path in your home directory:
~/ansible_collections/<NAMESPACE>/<COLLECTION_NAME>. For instance, in case of thecommunity.generalcollection, it will be~/ansible_collections/community/general- If your collection is hosted on a remote server such as GitHub, clone it to that path as follows:
git clone <COLLECTION_REPO_URL> ~/ansible_collections/<NAMESPACE>/<COLLECTION_NAME>
How to run
[!NOTE] To run sanity tests using podman or docker, always use the default docker image by passing the
--dockerargument without specifying the image name.
- When testing files in a collection, change your location to your collection directory you created while
setting up your environment<set_up_env_to_run_tests>:
cd ~/ansible_collections/<NAMESPACE>/<COLLECTION_NAME>
- To run all sanity tests in a container:
ansible-test sanity --docker
- To run a
specific test<all_sanity_tests>, add the--test <NAME>argument, for example,--test validate-modules.- To list available tests, run:
ansible-test sanity --list-tests
- To list available tests, run:
- To include disabled tests, add the
--allow-disabledargument.
Available Tests
See the full list of sanity tests <all_sanity_tests>, which also details how to fix identified issues.
这篇文档对你有帮助吗?
谢谢你的反馈!