mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-29 03:30:22 -07:00
This makes the module args parser more functional to eliminate side effects and eliminiates the 'return None' error path
to make sure we are handling more use cases. Some paths are not yet complete, including most likely handling of the 'raw' module.
This commit is contained in:
parent
56b6cb5328
commit
79f41d9c1a
3 changed files with 165 additions and 224 deletions
|
@ -13,20 +13,17 @@ class TestModArgsDwim(unittest.TestCase):
|
|||
self.m = ModuleArgsParser()
|
||||
pass
|
||||
|
||||
def _debug(self, mod, args, to):
|
||||
print "RETURNED module = %s" % mod
|
||||
print " args = %s" % args
|
||||
print " to = %s" % to
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_action_to_shell(self):
|
||||
mod, args, to = self.m.parse(dict(action='shell echo hi'))
|
||||
assert mod == 'command'
|
||||
assert args == dict(
|
||||
_raw_params = 'echo hi',
|
||||
_uses_shell = True,
|
||||
)
|
||||
assert to is None
|
||||
|
||||
def test_basic_shell(self):
|
||||
mod, args, to = self.m.parse(dict(shell='echo hi'))
|
||||
self._debug(mod, args, to)
|
||||
assert mod == 'command'
|
||||
assert args == dict(
|
||||
_raw_params = 'echo hi',
|
||||
|
@ -36,6 +33,7 @@ class TestModArgsDwim(unittest.TestCase):
|
|||
|
||||
def test_basic_command(self):
|
||||
mod, args, to = self.m.parse(dict(command='echo hi'))
|
||||
self._debug(mod, args, to)
|
||||
assert mod == 'command'
|
||||
assert args == dict(
|
||||
_raw_params = 'echo hi',
|
||||
|
@ -44,6 +42,7 @@ class TestModArgsDwim(unittest.TestCase):
|
|||
|
||||
def test_shell_with_modifiers(self):
|
||||
mod, args, to = self.m.parse(dict(shell='/bin/foo creates=/tmp/baz removes=/tmp/bleep'))
|
||||
self._debug(mod, args, to)
|
||||
assert mod == 'command'
|
||||
assert args == dict(
|
||||
creates = '/tmp/baz',
|
||||
|
@ -55,30 +54,35 @@ class TestModArgsDwim(unittest.TestCase):
|
|||
|
||||
def test_normal_usage(self):
|
||||
mod, args, to = self.m.parse(dict(copy='src=a dest=b'))
|
||||
self._debug(mod, args, to)
|
||||
assert mod == 'copy'
|
||||
assert args == dict(src='a', dest='b')
|
||||
assert to is None
|
||||
|
||||
def test_complex_args(self):
|
||||
mod, args, to = self.m.parse(dict(copy=dict(src='a', dest='b')))
|
||||
self._debug(mod, args, to)
|
||||
assert mod == 'copy'
|
||||
assert args == dict(src='a', dest='b')
|
||||
assert to is None
|
||||
|
||||
def test_action_with_complex(self):
|
||||
mod, args, to = self.m.parse(dict(action=dict(module='copy', src='a', dest='b')))
|
||||
self._debug(mod, args, to)
|
||||
assert mod == 'copy'
|
||||
assert args == dict(src='a', dest='b')
|
||||
assert to is None
|
||||
|
||||
def test_action_with_complex_and_complex_args(self):
|
||||
mod, args, to = self.m.parse(dict(action=dict(module='copy', args=dict(src='a', dest='b'))))
|
||||
self._debug(mod, args, to)
|
||||
assert mod == 'copy'
|
||||
assert args == dict(src='a', dest='b')
|
||||
assert to is None
|
||||
|
||||
def test_local_action_string(self):
|
||||
mod, args, to = self.m.parse(dict(local_action='copy src=a dest=b'))
|
||||
self._debug(mod, args, to)
|
||||
assert mod == 'copy'
|
||||
assert args == dict(src='a', dest='b')
|
||||
assert to is 'localhost'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue