Skip to content

Commit 017513e

Browse files
committed
Try to fix callback tests.
1 parent 2f619ac commit 017513e

File tree

4 files changed

+66
-34
lines changed

4 files changed

+66
-34
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
# Copyright (c) Ansible Project
3+
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4+
# SPDX-License-Identifier: GPL-3.0-or-later
5+
6+
dependencies:
7+
- setup_callback_helper

tests/integration/targets/callback/tasks/main.yml

+1-34
Original file line numberDiff line numberDiff line change
@@ -50,44 +50,11 @@
5050
- name: Assert test output equals expected output
5151
assert:
5252
that: result.output.differences | length == 0
53-
loop: "{{ results }}"
53+
loop: "{{ outputs.results | callback_results_extractor }}"
5454
loop_control:
5555
loop_var: result
5656
label: "{{ result.name }}"
5757
register: assertions
58-
vars:
59-
results: >-
60-
{%- set results = [] -%}
61-
{%- for result in outputs.results -%}
62-
{%- set differences = [] -%}
63-
{%- for i in range([result.test.expected_output | count, result.stdout_lines | count] | max) -%}
64-
{%- set line = "line_%s" | format(i+1) -%}
65-
{%- set test_line = result.stdout_lines[i] | default(none) -%}
66-
{%- set expected_lines = result.test.expected_output[i] | default(none) -%}
67-
{%- if expected_lines is not string and expected_lines is not none -%}
68-
{%- if test_line not in expected_lines -%}
69-
{{- differences.append({
70-
line: {
71-
'expected_one_of': expected_lines,
72-
'got': test_line }}) -}}
73-
{%- endif -%}
74-
{%- else -%}
75-
{%- if expected_lines != test_line -%}
76-
{{- differences.append({
77-
line: {
78-
'expected': expected_lines,
79-
'got': test_line }}) -}}
80-
{%- endif -%}
81-
{%- endif -%}
82-
{%- endfor -%}
83-
{{- results.append({
84-
'name': result.test.name,
85-
'output': {
86-
'differences': differences,
87-
'expected': result.test.expected_output,
88-
'got': result.stdout_lines }}) -}}
89-
{%- endfor -%}
90-
{{- results -}}
9158

9259
always:
9360
- name: Remove temporary playbooks
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright (c) Ansible Project
2+
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
from __future__ import (absolute_import, division, print_function)
6+
__metaclass__ = type
7+
8+
from ansible.module_utils.six import string_types
9+
10+
11+
def callback_results_extractor(outputs_results):
12+
results = []
13+
for result in outputs_results:
14+
differences = []
15+
expected_output = result['test']['expected_output']
16+
stdout_lines = result['stdout_lines']
17+
for i in range(max(len(expected_output), len(stdout_lines))):
18+
line = "line_%s" % (i + 1)
19+
test_line = stdout_lines[i] if i < len(stdout_lines) else None
20+
expected_lines = expected_output[i] if i < len(expected_output) else None
21+
if not isinstance(expected_lines, string_types) and expected_lines is not None:
22+
if test_line not in expected_lines:
23+
differences.append({
24+
'line': {
25+
'expected_one_of': expected_lines,
26+
'got': test_line,
27+
}
28+
})
29+
else:
30+
if test_line != expected_lines:
31+
differences.append({
32+
'line': {
33+
'expected': expected_lines,
34+
'got': test_line,
35+
}
36+
})
37+
results.append({
38+
'name': result['test']['name'],
39+
'output': {
40+
'differences': differences,
41+
'expected': expected_output,
42+
'got': stdout_lines,
43+
},
44+
})
45+
return results
46+
47+
48+
class FilterModule:
49+
''' Jinja2 compat filters '''
50+
51+
def filters(self):
52+
return {
53+
'callback_results_extractor': callback_results_extractor,
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
# Copyright (c) Ansible Project
3+
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4+
# SPDX-License-Identifier: GPL-3.0-or-later

0 commit comments

Comments
 (0)