forked from ansible/ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ansible-test - fix up relative util import for powershell validate-mo…
…dules (ansible#69753) * ansible-test - fix up relative util import for powershell validate-modules * Use different tactic for generic group * Use python 2 and 3
- Loading branch information
Showing
19 changed files
with
302 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
shippable/generic/group1 # Runs in the default test container so access to tools like pwsh |
21 changes: 21 additions & 0 deletions
21
...n/targets/ansible-test-docker/ansible_collections/ns/col/plugins/doc_fragments/ps_util.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (c) 2020 Ansible Project | ||
# 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 | ||
|
||
|
||
class ModuleDocFragment: | ||
|
||
DOCUMENTATION = r''' | ||
options: | ||
option1: | ||
description: | ||
- Test description | ||
required: yes | ||
aliases: | ||
- alias1 | ||
type: str | ||
''' |
16 changes: 16 additions & 0 deletions
16
...n/targets/ansible-test-docker/ansible_collections/ns/col/plugins/module_utils/PSUtil.psm1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright (c) 2020 Ansible Project | ||
# # Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause) | ||
|
||
Function Get-PSUtilSpec { | ||
<# | ||
.SYNOPSIS | ||
Shared util spec test | ||
#> | ||
@{ | ||
options = @{ | ||
option1 = @{ type = 'str'; required = $true; aliases = 'alias1' } | ||
} | ||
} | ||
} | ||
|
||
Export-ModuleMember -Function Get-PSUtilSpec |
6 changes: 6 additions & 0 deletions
6
...on/targets/ansible-test-docker/ansible_collections/ns/col/plugins/module_utils/my_util.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from __future__ import absolute_import, division, print_function | ||
__metaclass__ = type | ||
|
||
|
||
def hello(name): | ||
return 'Hello %s' % name |
46 changes: 46 additions & 0 deletions
46
...tegration/targets/ansible-test-docker/ansible_collections/ns/col/plugins/modules/hello.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
18 changes: 18 additions & 0 deletions
18
.../targets/ansible-test-docker/ansible_collections/ns/col/plugins/modules/win_util_args.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!powershell | ||
|
||
# Copyright (c) 2020 Ansible Project | ||
# # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
#AnsibleRequires -CSharpUtil Ansible.Basic | ||
#AnsibleRequires -PowerShell ..module_utils.PSUtil | ||
|
||
$spec = @{ | ||
options = @{ | ||
my_opt = @{ type = "str"; required = $true } | ||
} | ||
} | ||
$util_spec = Get-PSUtilSpec | ||
$spec.options += $util_spec.options | ||
|
||
$module = [Ansible.Basic.AnsibleModule]::Create($args, $spec) | ||
$module.ExitJson() |
39 changes: 39 additions & 0 deletions
39
...n/targets/ansible-test-docker/ansible_collections/ns/col/plugins/modules/win_util_args.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (c) 2020 Ansible Project | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
|
||
ANSIBLE_METADATA = {'metadata_version': '1.1', | ||
'status': ['stableinterface'], | ||
'supported_by': 'core'} | ||
|
||
DOCUMENTATION = r''' | ||
--- | ||
module: win_util_args | ||
short_description: Short description | ||
description: | ||
- Some test description for the module | ||
options: | ||
my_opt: | ||
description: | ||
- Test description | ||
required: yes | ||
type: str | ||
extends_documentation_fragment: | ||
- ns.col.ps_util | ||
author: | ||
- Ansible Test (@ansible) | ||
''' | ||
|
||
EXAMPLES = r''' | ||
- win_util_args: | ||
option1: test | ||
my_opt: test | ||
''' | ||
|
||
RETURN = r''' | ||
# | ||
''' |
7 changes: 7 additions & 0 deletions
7
...e-test-docker/ansible_collections/ns/col/tests/integration/targets/minimal/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
- hello: | ||
name: Ansibull | ||
register: hello | ||
|
||
- assert: | ||
that: | ||
- hello.message == 'Hello Ansibull' |
8 changes: 8 additions & 0 deletions
8
...le-test-docker/ansible_collections/ns/col/tests/unit/plugins/module_utils/test_my_util.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
8 changes: 8 additions & 0 deletions
8
...s/ansible-test-docker/ansible_collections/ns/col/tests/unit/plugins/modules/test_hello.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') |
18 changes: 18 additions & 0 deletions
18
test/integration/targets/ansible-test-docker/collection-tests/docker.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eux -o pipefail | ||
|
||
cp -a "${TEST_DIR}/ansible_collections" "${WORK_DIR}" | ||
cd "${WORK_DIR}/ansible_collections/ns/col" | ||
|
||
# common args for all tests | ||
# because we are running in shippable/generic/ we are already in the default docker container | ||
common=(--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[@]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu -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 | ||
|
||
export TEST_DIR | ||
export WORK_DIR | ||
|
||
TEST_DIR="$PWD" | ||
|
||
for test in collection-tests/*.sh; do | ||
WORK_DIR="${tmp_dir}/$(basename "${test}" ".sh")" | ||
mkdir "${WORK_DIR}" | ||
echo "**********************************************************************" | ||
echo "TEST: ${test}: STARTING" | ||
"${test}" "${@}" || (echo "TEST: ${test}: FAILED" && exit 1) | ||
echo "TEST: ${test}: PASSED" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.