mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
xml: fail for non-string values (#11959)
* fix(xml): coerce boolean values to string with a warning Fixes #7171 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * test(xml): add integration tests for boolean value handling Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * changelog: add fragment for PR 11959 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * adjustments from review * test(xml): update boolean-value integration tests to expect failure Now that xml fails on non-string values, replace the old success-path tests with failure assertions and add a positive test for quoted strings. Remove the no-longer-needed result XML fixtures. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * adjustments from review * fix(xml): correct boolean test assertions to match actual error message format Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -60,6 +60,7 @@
|
||||
- include_tasks: test-remove-element.yml
|
||||
- include_tasks: test-remove-element-nochange.yml
|
||||
- include_tasks: test-set-attribute-value.yml
|
||||
- include_tasks: test-set-attribute-value-boolean.yml
|
||||
- include_tasks: test-set-children-elements.yml
|
||||
- include_tasks: test-set-children-elements-level.yml
|
||||
- include_tasks: test-set-children-elements-value.yml
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
---
|
||||
# Copyright (c) Ansible Project
|
||||
# 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
|
||||
|
||||
# Regression test for https://github.com/ansible-collections/community.general/issues/7171
|
||||
# Passing an unquoted YAML boolean as `value` must now fail with an explicit error.
|
||||
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: "Set '/business/rating/@subjective' to boolean false (unquoted YAML boolean) - must fail"
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/rating
|
||||
attribute: subjective
|
||||
value: false
|
||||
register: set_attribute_boolean_false
|
||||
ignore_errors: true
|
||||
|
||||
- name: Assert that passing a boolean attribute value raises an error
|
||||
assert:
|
||||
that:
|
||||
- set_attribute_boolean_false is failed
|
||||
- "'was parsed for' in set_attribute_boolean_false.msg"
|
||||
- "'attribute' in set_attribute_boolean_false.msg"
|
||||
|
||||
|
||||
- name: "Set '/business/rating' text content to boolean true (unquoted YAML boolean) - must fail"
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/rating
|
||||
value: true
|
||||
register: set_element_boolean_true
|
||||
ignore_errors: true
|
||||
|
||||
- name: Assert that passing a boolean element value raises an error
|
||||
assert:
|
||||
that:
|
||||
- set_element_boolean_true is failed
|
||||
- "'was parsed for' in set_element_boolean_true.msg"
|
||||
- "'element text' in set_element_boolean_true.msg"
|
||||
|
||||
|
||||
- name: "Set '/business/rating/@subjective' to quoted string 'false' - must succeed"
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/rating
|
||||
attribute: subjective
|
||||
value: "false"
|
||||
register: set_attribute_string_false
|
||||
|
||||
- name: Assert that passing a quoted string attribute value succeeds
|
||||
assert:
|
||||
that:
|
||||
- set_attribute_string_false is changed
|
||||
Reference in New Issue
Block a user