Add initial ansible-test tests for collections. (#68533)

pull/68545/head
Matt Clay 4 years ago committed by GitHub
parent 735885d57c
commit 0fb5593abf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
shippable/posix/group1
skip/aix

@ -0,0 +1,6 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
def hello(name):
return 'Hello %s' % name

@ -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()

@ -0,0 +1,7 @@
- hello:
name: Ansibull
register: hello
- assert:
that:
- hello.message == 'Hello Ansibull'

@ -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'

@ -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')

@ -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[@]}"

@ -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

Loading…
Cancel
Save