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:
parent
4b6cd41512
commit
6385fbe038
2 changed files with 31 additions and 71 deletions
|
|
@ -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"
|
||||
...
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
...
|
||||
Loading…
Add table
Add a link
Reference in a new issue