Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 16 additions & 32 deletions tests/integration/targets/callback/filter_plugins/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/targets/callback/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

- name: Assert test output equals expected output
assert:
that: result.output.differences | length == 0
that: result.output.diff | length == 0
Copy link
Collaborator

@russoz russoz Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the RV name from differences to diff is a breaking change. Right? Cc: @felixfontein

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but that doesn't matter, since it's an internal plugin used only by the integration tests that cannot be used from anywhere else.

loop: "{{ outputs.results | callback_results_extractor }}"
loop_control:
loop_var: result
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/targets/callback_diy/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 *********************************************************************"
Expand Down