From 0fb5593abf0a703baadf2ef18ffde592c710993c Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Sun, 29 Mar 2020 09:04:27 -0700 Subject: [PATCH] Add initial ansible-test tests for collections. (#68533) --- test/integration/targets/ansible-test/aliases | 2 + .../ns/col/plugins/module_utils/my_util.py | 6 +++ .../ns/col/plugins/modules/hello.py | 46 +++++++++++++++++++ .../targets/minimal/tasks/main.yml | 7 +++ .../unit/plugins/module_utils/test_my_util.py | 8 ++++ .../tests/unit/plugins/modules/test_hello.py | 8 ++++ .../integration/targets/ansible-test/runme.sh | 24 ++++++++++ test/sanity/ignore.txt | 3 ++ 8 files changed, 104 insertions(+) create mode 100644 test/integration/targets/ansible-test/aliases create mode 100644 test/integration/targets/ansible-test/ansible_collections/ns/col/plugins/module_utils/my_util.py create mode 100644 test/integration/targets/ansible-test/ansible_collections/ns/col/plugins/modules/hello.py create mode 100644 test/integration/targets/ansible-test/ansible_collections/ns/col/tests/integration/targets/minimal/tasks/main.yml create mode 100644 test/integration/targets/ansible-test/ansible_collections/ns/col/tests/unit/plugins/module_utils/test_my_util.py create mode 100644 test/integration/targets/ansible-test/ansible_collections/ns/col/tests/unit/plugins/modules/test_hello.py create mode 100755 test/integration/targets/ansible-test/runme.sh diff --git a/test/integration/targets/ansible-test/aliases b/test/integration/targets/ansible-test/aliases new file mode 100644 index 00000000000..f8e28c7e469 --- /dev/null +++ b/test/integration/targets/ansible-test/aliases @@ -0,0 +1,2 @@ +shippable/posix/group1 +skip/aix diff --git a/test/integration/targets/ansible-test/ansible_collections/ns/col/plugins/module_utils/my_util.py b/test/integration/targets/ansible-test/ansible_collections/ns/col/plugins/module_utils/my_util.py new file mode 100644 index 00000000000..b9c531cf8aa --- /dev/null +++ b/test/integration/targets/ansible-test/ansible_collections/ns/col/plugins/module_utils/my_util.py @@ -0,0 +1,6 @@ +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + +def hello(name): + return 'Hello %s' % name diff --git a/test/integration/targets/ansible-test/ansible_collections/ns/col/plugins/modules/hello.py b/test/integration/targets/ansible-test/ansible_collections/ns/col/plugins/modules/hello.py new file mode 100644 index 00000000000..c8a0cf75a03 --- /dev/null +++ b/test/integration/targets/ansible-test/ansible_collections/ns/col/plugins/modules/hello.py @@ -0,0 +1,46 @@ +#!/usr/bin/python +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +DOCUMENTATION = ''' +module: hello +short_description: Hello test module +description: Hello test module. +options: + name: + description: Name to say hello to. + type: str +author: + - Ansible Core Team +''' + +EXAMPLES = ''' +- minimal: +''' + +RETURN = '''''' + +from ansible.module_utils.basic import AnsibleModule +from ..module_utils.my_util import hello + + +def main(): + module = AnsibleModule( + argument_spec=dict( + name=dict(type='str'), + ), + ) + + module.exit_json(**say_hello(module.params['name'])) + + +def say_hello(name): + return dict( + message=hello(name), + ) + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/ansible-test/ansible_collections/ns/col/tests/integration/targets/minimal/tasks/main.yml b/test/integration/targets/ansible-test/ansible_collections/ns/col/tests/integration/targets/minimal/tasks/main.yml new file mode 100644 index 00000000000..c45c199cf3f --- /dev/null +++ b/test/integration/targets/ansible-test/ansible_collections/ns/col/tests/integration/targets/minimal/tasks/main.yml @@ -0,0 +1,7 @@ +- hello: + name: Ansibull + register: hello + +- assert: + that: + - hello.message == 'Hello Ansibull' diff --git a/test/integration/targets/ansible-test/ansible_collections/ns/col/tests/unit/plugins/module_utils/test_my_util.py b/test/integration/targets/ansible-test/ansible_collections/ns/col/tests/unit/plugins/module_utils/test_my_util.py new file mode 100644 index 00000000000..7df87103767 --- /dev/null +++ b/test/integration/targets/ansible-test/ansible_collections/ns/col/tests/unit/plugins/module_utils/test_my_util.py @@ -0,0 +1,8 @@ +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +from .....plugins.module_utils.my_util import hello + + +def test_hello(): + assert hello('Ansibull') == 'Hello Ansibull' diff --git a/test/integration/targets/ansible-test/ansible_collections/ns/col/tests/unit/plugins/modules/test_hello.py b/test/integration/targets/ansible-test/ansible_collections/ns/col/tests/unit/plugins/modules/test_hello.py new file mode 100644 index 00000000000..95ee0574fac --- /dev/null +++ b/test/integration/targets/ansible-test/ansible_collections/ns/col/tests/unit/plugins/modules/test_hello.py @@ -0,0 +1,8 @@ +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +from .....plugins.modules.hello import say_hello + + +def test_say_hello(): + assert say_hello('Ansibull') == dict(message='Hello Ansibull') diff --git a/test/integration/targets/ansible-test/runme.sh b/test/integration/targets/ansible-test/runme.sh new file mode 100755 index 00000000000..d3c40f522d8 --- /dev/null +++ b/test/integration/targets/ansible-test/runme.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -eux -o pipefail + +# tests must be executed outside of the ansible source tree +# otherwise ansible-test will test the ansible source instead of the test collection +# the temporary directory provided by ansible-test resides within the ansible source tree +tmp_dir=$(mktemp -d) + +trap 'rm -rf "${tmp_dir}"' EXIT + +cp -a ansible_collections "${tmp_dir}" +cd "${tmp_dir}/ansible_collections/ns/col" + +# common args for all tests +common=(--venv --python "${ANSIBLE_TEST_PYTHON_VERSION}" --color --truncate 0 "${@}") + +# prime the venv to work around issue with PyYAML detection in ansible-test +ansible-test sanity "${common[@]}" --test ignores + +# tests +ansible-test sanity "${common[@]}" +ansible-test units "${common[@]}" +ansible-test integration "${common[@]}" diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt index f0f82e4a6de..f26cc4552ab 100644 --- a/test/sanity/ignore.txt +++ b/test/sanity/ignore.txt @@ -256,6 +256,9 @@ test/integration/targets/ansible-runner/files/adhoc_example1.py future-import-bo test/integration/targets/ansible-runner/files/adhoc_example1.py metaclass-boilerplate test/integration/targets/ansible-runner/files/playbook_example1.py future-import-boilerplate test/integration/targets/ansible-runner/files/playbook_example1.py metaclass-boilerplate +test/integration/targets/ansible-test/ansible_collections/ns/col/plugins/modules/hello.py pylint:relative-beyond-top-level +test/integration/targets/ansible-test/ansible_collections/ns/col/tests/unit/plugins/module_utils/test_my_util.py pylint:relative-beyond-top-level +test/integration/targets/ansible-test/ansible_collections/ns/col/tests/unit/plugins/modules/test_hello.py pylint:relative-beyond-top-level test/integration/targets/async/library/async_test.py future-import-boilerplate test/integration/targets/async/library/async_test.py metaclass-boilerplate test/integration/targets/async_fail/library/async_test.py future-import-boilerplate