Add tests for new alias deprecation functionality (#61476)
* Add tests for the alias deprecation added in #61245
This commit is contained in:
parent
59afffa334
commit
d49d52eb5f
3 changed files with 35 additions and 0 deletions
|
@ -0,0 +1,15 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
from ansible.module_utils.facts import data
|
||||||
|
|
||||||
|
results = {"data": data}
|
||||||
|
|
||||||
|
arg_spec = dict(
|
||||||
|
foo=dict(type='str', aliases=['baz'], deprecated_aliases=[dict(name='baz', version='9.99')])
|
||||||
|
)
|
||||||
|
|
||||||
|
AnsibleModule(argument_spec=arg_spec).exit_json(**results)
|
|
@ -49,3 +49,14 @@
|
||||||
that:
|
that:
|
||||||
- result is failed
|
- result is failed
|
||||||
- result['msg'] == "Could not find imported module support code for test_failure. Looked for either foo.py or zebra.py"
|
- result['msg'] == "Could not find imported module support code for test_failure. Looked for either foo.py or zebra.py"
|
||||||
|
|
||||||
|
- name: Test that alias deprecation works
|
||||||
|
test_alias_deprecation:
|
||||||
|
baz: 'bar'
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: Assert that the deprecation message is given correctly
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result.deprecations[0].msg == "Alias 'baz' is deprecated. See the module docs for more information"
|
||||||
|
- result.deprecations[0].version == '9.99'
|
||||||
|
|
|
@ -102,6 +102,7 @@ def complex_argspec():
|
||||||
bar3=dict(type='list', elements='path'),
|
bar3=dict(type='list', elements='path'),
|
||||||
zardoz=dict(choices=['one', 'two']),
|
zardoz=dict(choices=['one', 'two']),
|
||||||
zardoz2=dict(type='list', choices=['one', 'two', 'three']),
|
zardoz2=dict(type='list', choices=['one', 'two', 'three']),
|
||||||
|
zardoz3=dict(type='str', aliases=['zodraz'], deprecated_aliases=[dict(name='zodraz', version='9.99')]),
|
||||||
)
|
)
|
||||||
mut_ex = (('bar', 'bam'), ('bing', 'bang', 'bong'))
|
mut_ex = (('bar', 'bam'), ('bing', 'bang', 'bong'))
|
||||||
req_to = (('bam', 'baz'),)
|
req_to = (('bam', 'baz'),)
|
||||||
|
@ -332,6 +333,14 @@ class TestComplexArgSpecs:
|
||||||
assert am.params['bar3'][0].startswith('/')
|
assert am.params['bar3'][0].startswith('/')
|
||||||
assert am.params['bar3'][1] == 'test/'
|
assert am.params['bar3'][1] == 'test/'
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('stdin', [{'foo': 'hello', 'zodraz': 'one'}], indirect=['stdin'])
|
||||||
|
def test_deprecated_alias(self, capfd, mocker, stdin, complex_argspec):
|
||||||
|
"""Test a deprecated alias"""
|
||||||
|
am = basic.AnsibleModule(**complex_argspec)
|
||||||
|
|
||||||
|
assert "Alias 'zodraz' is deprecated." in am._deprecations[0]['msg']
|
||||||
|
assert am._deprecations[0]['version'] == '9.99'
|
||||||
|
|
||||||
|
|
||||||
class TestComplexOptions:
|
class TestComplexOptions:
|
||||||
"""Test arg spec options"""
|
"""Test arg spec options"""
|
||||||
|
|
Loading…
Reference in a new issue