mirror of
https://github.com/ansible-collections/community.routeros.git
synced 2025-06-22 09:53:32 +02:00
fix(api): fixed a bug when splitting the argument string (#45)
* fix(api): fixed a bug when splitting the argument string * fix(api): added the shlex module for splitting * fix(api): added the shlex module for splitting * fix(api): moved shlex.split to self method split_params * Fix indentation. * Implement custom splitting algorithm. * Raise AssertionError in case of internal error. * Update plugins/modules/api.py this is correct thanks ! Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Nikolay Dachev <nikolay@dachev.info>
This commit is contained in:
parent
f432b1fa07
commit
5042905471
3 changed files with 135 additions and 6 deletions
|
@ -288,3 +288,33 @@ class TestRouterosApiModule(ModuleTestCase):
|
|||
|
||||
result = exc.exception.args[0]
|
||||
self.assertEqual(result['changed'], False)
|
||||
|
||||
|
||||
TEST_SPLIT_ROUTEROS = [
|
||||
('', []),
|
||||
(' ', []),
|
||||
(r'a b c', ['a', 'b', 'c']),
|
||||
(r'a=b c d=e', ['a=b', 'c', 'd=e']),
|
||||
(r'a="b f" c d=e', ['a=b f', 'c', 'd=e']),
|
||||
(r'a="b\"f" c\FF d=\"e', ['a=b"f', '\xff', 'c', 'd="e']),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("command, result", TEST_SPLIT_ROUTEROS)
|
||||
def test_split_routeros(command, result):
|
||||
result_ = api.split_routeros(command)
|
||||
print(result_, result)
|
||||
assert result_ == result
|
||||
|
||||
|
||||
TEST_SPLIT_ROUTEROS_ERRORS = [
|
||||
(r'a="b\"f" c\FF d="e', 'Unexpected end of string during escaped parameter'),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("command, message", TEST_SPLIT_ROUTEROS_ERRORS)
|
||||
def test_split_routeros_errors(command, message):
|
||||
with pytest.raises(api.ParseError) as exc:
|
||||
api.split_routeros(command)
|
||||
print(exc.value.args[0], message)
|
||||
assert exc.value.args[0] == message
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue