mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 05:10:22 -07:00
New v2 ModuleArgsParser code and fixing up tests/other task code
This commit is contained in:
parent
bbd9921dbd
commit
c83a833740
5 changed files with 350 additions and 96 deletions
|
@ -13,67 +13,69 @@ class TestModArgsDwim(unittest.TestCase):
|
|||
pass
|
||||
|
||||
def test_action_to_shell(self):
|
||||
mod, args, to = self.m.parse('action', 'shell echo hi')
|
||||
assert mod == 'shell'
|
||||
mod, args, to = self.m.parse(dict(action='shell echo hi'))
|
||||
assert mod == 'command'
|
||||
assert args == dict(
|
||||
free_form = 'echo hi',
|
||||
use_shell = True
|
||||
_raw_params = 'echo hi',
|
||||
_uses_shell = True,
|
||||
)
|
||||
assert to is None
|
||||
|
||||
def test_basic_shell(self):
|
||||
mod, args, to = self.m.parse('shell', 'echo hi')
|
||||
assert mod == 'shell'
|
||||
mod, args, to = self.m.parse(dict(shell='echo hi'))
|
||||
assert mod == 'command'
|
||||
assert args == dict(
|
||||
free_form = 'echo hi',
|
||||
use_shell = True
|
||||
_raw_params = 'echo hi',
|
||||
_uses_shell = True,
|
||||
)
|
||||
assert to is None
|
||||
|
||||
def test_basic_command(self):
|
||||
mod, args, to = self.m.parse('command', 'echo hi')
|
||||
mod, args, to = self.m.parse(dict(command='echo hi'))
|
||||
assert mod == 'command'
|
||||
assert args == dict(
|
||||
free_form = 'echo hi',
|
||||
use_shell = False
|
||||
_raw_params = 'echo hi',
|
||||
)
|
||||
assert to is None
|
||||
|
||||
def test_shell_with_modifiers(self):
|
||||
mod, args, to = self.m.parse('shell', '/bin/foo creates=/tmp/baz removes=/tmp/bleep')
|
||||
assert mod == 'shell'
|
||||
mod, args, to = self.m.parse(dict(shell='/bin/foo creates=/tmp/baz removes=/tmp/bleep'))
|
||||
assert mod == 'command'
|
||||
assert args == dict(
|
||||
free_form = 'echo hi',
|
||||
use_shell = False,
|
||||
creates = '/tmp/baz',
|
||||
removes = '/tmp/bleep'
|
||||
creates = '/tmp/baz',
|
||||
removes = '/tmp/bleep',
|
||||
_raw_params = '/bin/foo',
|
||||
_uses_shell = True,
|
||||
)
|
||||
assert to is None
|
||||
|
||||
def test_normal_usage(self):
|
||||
mod, args, to = self.m.parse('copy', 'src=a dest=b')
|
||||
mod, args, to = self.m.parse(dict(copy='src=a dest=b'))
|
||||
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('copy', dict(src=a, dest=b))
|
||||
mod, args, to = self.m.parse(dict(copy=dict(src='a', dest='b')))
|
||||
assert mod == 'copy'
|
||||
assert args == dict(src = 'a', dest = 'b')
|
||||
assert args == dict(src='a', dest='b')
|
||||
assert to is None
|
||||
|
||||
def test_action_with_complex(self):
|
||||
mod, args, to = self.m.parse('action', dict(module='copy',src='a',dest='b'))
|
||||
assert mod == 'action'
|
||||
assert args == dict(src = 'a', dest = 'b')
|
||||
mod, args, to = self.m.parse(dict(action=dict(module='copy', src='a', dest='b')))
|
||||
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'))))
|
||||
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('local_action', 'copy src=a dest=b')
|
||||
mod, args, to = self.m.parse(dict(local_action='copy src=a dest=b'))
|
||||
assert mod == 'copy'
|
||||
assert args == dict(src=a, dest=b)
|
||||
assert args == dict(src='a', dest='b')
|
||||
assert to is 'localhost'
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -36,13 +36,14 @@ class TestTask(unittest.TestCase):
|
|||
t = Task.load(basic_shell_task)
|
||||
assert t is not None
|
||||
assert t.name == basic_shell_task['name']
|
||||
assert t.action == 'shell'
|
||||
assert t.args == 'echo hi'
|
||||
assert t.action == 'command'
|
||||
assert t.args == dict(_raw_params='echo hi', _uses_shell=True)
|
||||
|
||||
def test_load_task_kv_form(self):
|
||||
t = Task.load(kv_shell_task)
|
||||
assert t.action == 'shell'
|
||||
#assert t.args == 'echo hi'
|
||||
print "task action is %s" % t.action
|
||||
assert t.action == 'command'
|
||||
assert t.args == dict(_raw_params='echo hi', _uses_shell=True)
|
||||
|
||||
def test_task_auto_name(self):
|
||||
assert 'name' not in kv_shell_task
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue