From 6385fbe038419a224c3bf4bf5c48efe19d59bacc Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 23 Feb 2026 06:30:35 +0100 Subject: [PATCH] [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 e118b23ba0359eb463b408f50bb95d3acf09ccbb) Co-authored-by: Felix Fontein --- .../targets/filter_from_ini/tasks/main.yml | 94 ++++++------------- .../targets/filter_from_ini/vars/main.yml | 8 -- 2 files changed, 31 insertions(+), 71 deletions(-) delete mode 100644 tests/integration/targets/filter_from_ini/vars/main.yml diff --git a/tests/integration/targets/filter_from_ini/tasks/main.yml b/tests/integration/targets/filter_from_ini/tasks/main.yml index 8f037eecd3..9ee0d8240a 100644 --- a/tests/integration/targets/filter_from_ini/tasks/main.yml +++ b/tests/integration/targets/filter_from_ini/tasks/main.yml @@ -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) # SPDX-License-Identifier: GPL-3.0-or-later -- name: 'Define ini_test_dict' - ansible.builtin.set_fact: - ini_test_dict: - section_name: - key_name: 'key value' - - 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: | +- name: Basic test + ansible.builtin.assert: + that: + - ini_file_content | community.general.from_ini == ini_test_dict + vars: + ini_file_content: | [section_name] key_name = key value [another_section] connection = ssh + [empty section] + [interpolate_test] interpolate_test_key = % + ini_test_dict: + section_name: + key_name: key value -- name: 'Slurp the test file: {{ ini_test_file }}' - ansible.builtin.slurp: - src: '{{ ini_test_file }}' - register: 'ini_file_content' + another_section: + connection: ssh -- name: >- - Ensure defined ini_test_dict is the same when retrieved - from {{ ini_test_file }} + empty section: {} + + interpolate_test: + interpolate_test_key: '%' + +- name: Test delimiters ansible.builtin.assert: that: - - 'ini_file_content.content | b64decode | community.general.from_ini == - ini_test_dict' - -- name: 'Define another ini_test_dict' - ansible.builtin.set_fact: + - ini_file_content | community.general.from_ini(delimiters=["="]) == ini_test_dict + vars: + ini_file_content: | + [section_name] + key_name * : with spaces = key value ini_test_dict: section_name: 'key_name * : with spaces': 'key value' -- name: 'Write another INI file that reflects ini_test_dict to {{ ini_test_file }}' - 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 }}' +- name: Try parsing the bad file with from_ini ansible.builtin.debug: - var: ini_bad_file_content | b64decode | community.general.from_ini - register: 'ini_bad_file_debug' + var: ini_bad_file_content | community.general.from_ini + vars: + ini_bad_file_content: | + Testing a not INI formatted file. + register: ini_bad_file_debug ignore_errors: true - name: 'Ensure from_ini raised the correct exception' ansible.builtin.assert: that: + - ini_bad_file_debug is failed - "'from_ini failed to parse given string' in ini_bad_file_debug.msg" - "'File contains no section headers' in ini_bad_file_debug.msg" -... diff --git a/tests/integration/targets/filter_from_ini/vars/main.yml b/tests/integration/targets/filter_from_ini/vars/main.yml deleted file mode 100644 index 8c4d793275..0000000000 --- a/tests/integration/targets/filter_from_ini/vars/main.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -# Copyright (c) 2023, Steffen Scheib -# 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' -...