mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-27 04:41:26 -07:00
bugfixes to JSON junk filter, added unit/integration tests to exercise (#17834)
This commit is contained in:
parent
657506cddd
commit
aa0ad073b8
7 changed files with 272 additions and 84 deletions
|
@ -556,42 +556,3 @@ class TestActionBase(unittest.TestCase):
|
|||
play_context.make_become_cmd.assert_called_once_with("ECHO SAME", executable=None)
|
||||
finally:
|
||||
C.BECOME_ALLOW_SAME_USER = become_allow_same_user
|
||||
|
||||
|
||||
# Note: Using nose's generator test cases here so we can't inherit from
|
||||
# unittest.TestCase
|
||||
class TestFilterNonJsonLines(object):
|
||||
parsable_cases = (
|
||||
(u'{"hello": "world"}', u'{"hello": "world"}'),
|
||||
(u'{"hello": "world"}\n', u'{"hello": "world"}'),
|
||||
(u'{"hello": "world"} ', u'{"hello": "world"} '),
|
||||
(u'{"hello": "world"} \n', u'{"hello": "world"} '),
|
||||
(u'Message of the Day\n{"hello": "world"}', u'{"hello": "world"}'),
|
||||
(u'{"hello": "world"}\nEpilogue', u'{"hello": "world"}'),
|
||||
(u'Several\nStrings\nbefore\n{"hello": "world"}\nAnd\nAfter\n', u'{"hello": "world"}'),
|
||||
(u'{"hello": "world",\n"olá": "mundo"}', u'{"hello": "world",\n"olá": "mundo"}'),
|
||||
(u'\nPrecedent\n{"hello": "world",\n"olá": "mundo"}\nAntecedent', u'{"hello": "world",\n"olá": "mundo"}'),
|
||||
)
|
||||
|
||||
unparsable_cases = (
|
||||
u'No json here',
|
||||
u'"olá": "mundo"',
|
||||
u'{"No json": "ending"',
|
||||
u'{"wrong": "ending"]',
|
||||
u'["wrong": "ending"}',
|
||||
)
|
||||
|
||||
def check_filter_non_json_lines(self, stdout_line, parsed):
|
||||
eq_(parsed, ActionBase._filter_non_json_lines(stdout_line))
|
||||
|
||||
def test_filter_non_json_lines(self):
|
||||
for stdout_line, parsed in self.parsable_cases:
|
||||
yield self.check_filter_non_json_lines, stdout_line, parsed
|
||||
|
||||
@raises(ValueError)
|
||||
def check_unparsable_filter_non_json_lines(self, stdout_line):
|
||||
ActionBase._filter_non_json_lines(stdout_line)
|
||||
|
||||
def test_unparsable_filter_non_json_lines(self):
|
||||
for stdout_line in self.unparsable_cases:
|
||||
yield self.check_unparsable_filter_non_json_lines, stdout_line
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue