1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-03-22 05:09:12 +00:00

[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 e118b23ba0)

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
patchback[bot] 2026-02-23 06:30:35 +01:00 committed by GitHub
parent 4b6cd41512
commit 6385fbe038
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 71 deletions

View file

@ -3,90 +3,58 @@
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
- name: 'Define ini_test_dict' - name: Basic test
ansible.builtin.set_fact: ansible.builtin.assert:
ini_test_dict: that:
section_name: - ini_file_content | community.general.from_ini == ini_test_dict
key_name: 'key value' vars:
ini_file_content: |
another_section:
connection: 'ssh'
interpolate_test:
interpolate_test_key: '%'
- name: 'Write INI file that reflects ini_test_dict to {{ ini_test_file }}'
ansible.builtin.copy:
dest: '{{ ini_test_file }}'
content: |
[section_name] [section_name]
key_name = key value key_name = key value
[another_section] [another_section]
connection = ssh connection = ssh
[empty section]
[interpolate_test] [interpolate_test]
interpolate_test_key = % interpolate_test_key = %
ini_test_dict:
section_name:
key_name: key value
- name: 'Slurp the test file: {{ ini_test_file }}' another_section:
ansible.builtin.slurp: connection: ssh
src: '{{ ini_test_file }}'
register: 'ini_file_content'
- name: >- empty section: {}
Ensure defined ini_test_dict is the same when retrieved
from {{ ini_test_file }} interpolate_test:
interpolate_test_key: '%'
- name: Test delimiters
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- 'ini_file_content.content | b64decode | community.general.from_ini == - ini_file_content | community.general.from_ini(delimiters=["="]) == ini_test_dict
ini_test_dict' vars:
ini_file_content: |
- name: 'Define another ini_test_dict' [section_name]
ansible.builtin.set_fact: key_name * : with spaces = key value
ini_test_dict: ini_test_dict:
section_name: section_name:
'key_name * : with spaces': 'key value' 'key_name * : with spaces': 'key value'
- name: 'Write another INI file that reflects ini_test_dict to {{ ini_test_file }}' - name: Try parsing the bad file with from_ini
ansible.builtin.copy:
dest: '{{ ini_test_file }}'
content: |
[section_name]
key_name * : with spaces = key value
- name: 'Slurp the other test file: {{ ini_test_file }}'
ansible.builtin.slurp:
src: '{{ ini_test_file }}'
register: 'ini_file_content'
- name: >-
Ensure defined ini_test_dict is the same when retrieved
from other {{ ini_test_file }}
ansible.builtin.assert:
that:
- 'ini_file_content.content | b64decode | community.general.from_ini(delimiters=["="]) ==
ini_test_dict'
- name: 'Create a file that is not INI formatted: {{ ini_bad_file }}'
ansible.builtin.copy:
dest: '{{ ini_bad_file }}'
content: |
Testing a not INI formatted file.
- name: 'Slurp the file that is not INI formatted: {{ ini_bad_file }}'
ansible.builtin.slurp:
src: '{{ ini_bad_file }}'
register: 'ini_bad_file_content'
- name: 'Try parsing the bad file with from_ini: {{ ini_bad_file }}'
ansible.builtin.debug: ansible.builtin.debug:
var: ini_bad_file_content | b64decode | community.general.from_ini var: ini_bad_file_content | community.general.from_ini
register: 'ini_bad_file_debug' vars:
ini_bad_file_content: |
Testing a not INI formatted file.
register: ini_bad_file_debug
ignore_errors: true ignore_errors: true
- name: 'Ensure from_ini raised the correct exception' - name: 'Ensure from_ini raised the correct exception'
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- ini_bad_file_debug is failed
- "'from_ini failed to parse given string' in ini_bad_file_debug.msg" - "'from_ini failed to parse given string' in ini_bad_file_debug.msg"
- "'File contains no section headers' in ini_bad_file_debug.msg" - "'File contains no section headers' in ini_bad_file_debug.msg"
...

View file

@ -1,8 +0,0 @@
---
# Copyright (c) 2023, Steffen Scheib <steffen@scheib.me>
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
ini_test_file: '/tmp/test.ini'
ini_bad_file: '/tmp/bad.file'
...