Skip to content

Commit 6385fbe

Browse files
[PR #11534/e118b23b backport][stable-12] Simplify and extend from_ini tests (#11535)
Simplify and extend from_ini tests (#11534) Simplify and extend from_ini tests. (cherry picked from commit e118b23) Co-authored-by: Felix Fontein <felix@fontein.de>
1 parent 4b6cd41 commit 6385fbe

File tree

2 files changed

+31
-71
lines changed

2 files changed

+31
-71
lines changed

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

Lines changed: 31 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,90 +3,58 @@
33
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
44
# SPDX-License-Identifier: GPL-3.0-or-later
55

6-
- name: 'Define ini_test_dict'
7-
ansible.builtin.set_fact:
8-
ini_test_dict:
9-
section_name:
10-
key_name: 'key value'
11-
12-
another_section:
13-
connection: 'ssh'
14-
15-
interpolate_test:
16-
interpolate_test_key: '%'
17-
18-
- name: 'Write INI file that reflects ini_test_dict to {{ ini_test_file }}'
19-
ansible.builtin.copy:
20-
dest: '{{ ini_test_file }}'
21-
content: |
6+
- name: Basic test
7+
ansible.builtin.assert:
8+
that:
9+
- ini_file_content | community.general.from_ini == ini_test_dict
10+
vars:
11+
ini_file_content: |
2212
[section_name]
2313
key_name = key value
2414
2515
[another_section]
2616
connection = ssh
2717
18+
[empty section]
19+
2820
[interpolate_test]
2921
interpolate_test_key = %
30-
31-
- name: 'Slurp the test file: {{ ini_test_file }}'
32-
ansible.builtin.slurp:
33-
src: '{{ ini_test_file }}'
34-
register: 'ini_file_content'
35-
36-
- name: >-
37-
Ensure defined ini_test_dict is the same when retrieved
38-
from {{ ini_test_file }}
39-
ansible.builtin.assert:
40-
that:
41-
- 'ini_file_content.content | b64decode | community.general.from_ini ==
42-
ini_test_dict'
43-
44-
- name: 'Define another ini_test_dict'
45-
ansible.builtin.set_fact:
4622
ini_test_dict:
4723
section_name:
48-
'key_name * : with spaces': 'key value'
24+
key_name: key value
4925

50-
- name: 'Write another INI file that reflects ini_test_dict to {{ ini_test_file }}'
51-
ansible.builtin.copy:
52-
dest: '{{ ini_test_file }}'
53-
content: |
54-
[section_name]
55-
key_name * : with spaces = key value
26+
another_section:
27+
connection: ssh
5628

57-
- name: 'Slurp the other test file: {{ ini_test_file }}'
58-
ansible.builtin.slurp:
59-
src: '{{ ini_test_file }}'
60-
register: 'ini_file_content'
29+
empty section: {}
6130

62-
- name: >-
63-
Ensure defined ini_test_dict is the same when retrieved
64-
from other {{ ini_test_file }}
31+
interpolate_test:
32+
interpolate_test_key: '%'
33+
34+
- name: Test delimiters
6535
ansible.builtin.assert:
6636
that:
67-
- 'ini_file_content.content | b64decode | community.general.from_ini(delimiters=["="]) ==
68-
ini_test_dict'
69-
70-
- name: 'Create a file that is not INI formatted: {{ ini_bad_file }}'
71-
ansible.builtin.copy:
72-
dest: '{{ ini_bad_file }}'
73-
content: |
74-
Testing a not INI formatted file.
75-
76-
- name: 'Slurp the file that is not INI formatted: {{ ini_bad_file }}'
77-
ansible.builtin.slurp:
78-
src: '{{ ini_bad_file }}'
79-
register: 'ini_bad_file_content'
37+
- ini_file_content | community.general.from_ini(delimiters=["="]) == ini_test_dict
38+
vars:
39+
ini_file_content: |
40+
[section_name]
41+
key_name * : with spaces = key value
42+
ini_test_dict:
43+
section_name:
44+
'key_name * : with spaces': 'key value'
8045

81-
- name: 'Try parsing the bad file with from_ini: {{ ini_bad_file }}'
46+
- name: Try parsing the bad file with from_ini
8247
ansible.builtin.debug:
83-
var: ini_bad_file_content | b64decode | community.general.from_ini
84-
register: 'ini_bad_file_debug'
48+
var: ini_bad_file_content | community.general.from_ini
49+
vars:
50+
ini_bad_file_content: |
51+
Testing a not INI formatted file.
52+
register: ini_bad_file_debug
8553
ignore_errors: true
8654

8755
- name: 'Ensure from_ini raised the correct exception'
8856
ansible.builtin.assert:
8957
that:
58+
- ini_bad_file_debug is failed
9059
- "'from_ini failed to parse given string' in ini_bad_file_debug.msg"
9160
- "'File contains no section headers' in ini_bad_file_debug.msg"
92-
...

tests/integration/targets/filter_from_ini/vars/main.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)