diff --git a/tests/integration/targets/callback/filter_plugins/helper.py b/tests/integration/targets/callback/filter_plugins/helper.py index 867dce6c750..03579625f42 100644 --- a/tests/integration/targets/callback/filter_plugins/helper.py +++ b/tests/integration/targets/callback/filter_plugins/helper.py @@ -5,44 +5,28 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -from ansible.module_utils.six import string_types +import difflib def callback_results_extractor(outputs_results): - results = [] - for result in outputs_results: - differences = [] - expected_output = result['test']['expected_output'] - stdout_lines = result['stdout_lines'] - for i in range(max(len(expected_output), len(stdout_lines))): - line = "line_%s" % (i + 1) - test_line = stdout_lines[i] if i < len(stdout_lines) else None - expected_lines = expected_output[i] if i < len(expected_output) else None - if not isinstance(expected_lines, string_types) and expected_lines is not None: - if test_line not in expected_lines: - differences.append({ - 'line': { - 'expected_one_of': expected_lines, - 'got': test_line, - } - }) - else: - if test_line != expected_lines: - differences.append({ - 'line': { - 'expected': expected_lines, - 'got': test_line, - } - }) - results.append({ + return [ + { 'name': result['test']['name'], 'output': { - 'differences': differences, - 'expected': expected_output, - 'got': stdout_lines, + 'diff': list( + difflib.unified_diff( + result['test']['expected_output'], + result['stdout_lines'], + fromfile="expected", + tofile="got", + ) + ), + 'expected': result['test']['expected_output'], + 'got': result['stdout_lines'], }, - }) - return results + } + for result in outputs_results + ] class FilterModule: diff --git a/tests/integration/targets/callback/tasks/main.yml b/tests/integration/targets/callback/tasks/main.yml index 88988f9bf90..d2ce9e1cc2d 100644 --- a/tests/integration/targets/callback/tasks/main.yml +++ b/tests/integration/targets/callback/tasks/main.yml @@ -49,7 +49,7 @@ - name: Assert test output equals expected output assert: - that: result.output.differences | length == 0 + that: result.output.diff | length == 0 loop: "{{ outputs.results | callback_results_extractor }}" loop_control: loop_var: result diff --git a/tests/integration/targets/callback_diy/tasks/main.yml b/tests/integration/targets/callback_diy/tasks/main.yml index f1d0c65a5d7..26191b5a9bc 100644 --- a/tests/integration/targets/callback_diy/tasks/main.yml +++ b/tests/integration/targets/callback_diy/tasks/main.yml @@ -276,9 +276,9 @@ - "ok: [testhost] => (item=sample item 3) => {" - " \"msg\": \"sample debug msg sample item 3\"" - "}" - - # Apparently a bug was fixed in Ansible, as before it ran through with "All items completed" - - "fatal: [testhost]: FAILED! => {\"msg\": \"All items completed\"}" - - "fatal: [testhost]: FAILED! => {\"msg\": \"One or more items failed\"}" + # Apparently a bug was fixed in Ansible, as before it ran through with "All items completed" + # - "fatal: [testhost]: FAILED! => {\"msg\": \"All items completed\"}" + - "fatal: [testhost]: FAILED! => {\"msg\": \"One or more items failed\"}" - "...ignoring" - "" - "PLAY RECAP *********************************************************************"