- Docker is running locally
- Connect API server and Connect Syncer running locally or on a remote server
- The
ansiblePython package & its binaries are installed on the test runner (i.e. your computer, the CI container).
Set the following environment variables before running the tests:
export OP_VAULT_ID=id_of_target_vault
export OP_CONNECT_HOST=http_url_to_connect_server # see comment
export OP_CONNECT_TOKEN=jwt_for_service_account
NOTE (macOS): If you are running the Connect server locally (i.e. not within a Docker container), set OP_CONNECT_HOST to http://docker.for.mac.host.internal:8080.
From the repository root, run make test/unit for Unit Tests and make test/integration for Integration Tests.
The script will:
- create a temporary directory (using mktemp)
- copy the collections under the
1passwordnamespace into the temporary directory - run
ansible-test <test_type> --docker {docker image} - remove the temp directory after exiting
You must place integration tests in the appropriate ./tests/integration/targets/ directory.
Module Tests
- Directory must match the name of the module.
- For example, you would place integration tests for
plugins/modules/foo.pyin a directory calledtests/integration/targets/foo/
Plugin Tests
- Add the plugin type to the directory name.
- Examples:
- Lookup Plugin named "foo" =>
./tests/integrations/targets/lookup_foo/ - Connection Plugin named "bar" =>
./tests/integration/targets/connection_bar/
- Lookup Plugin named "foo" =>
Debugging Ansible modules is not a simple as debugging normal Python modules.
See Ansible's Simple Debugging instructions for the current best practices.
If all else fails, adding a raise Exception(some_value) in a module will cause the module to exit and print the value of some_value.
Ansible 2.10 has a few issues with paths when running tests for Collections:
We also use Docker to avoid polluting local environments with test dependencies.