mirror of https://github.com/ansible/ansible.git
xml module: Better change detection, improved tests (#28460)
This PR includes: - Improvements to change-detection by comparing 2 objectified XML trees - Implement better integration tests by comparing 2 files using copypull/27817/head
parent
3302248616
commit
2634ef955a
@ -1,15 +1,29 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: '{{ role_path }}/fixtures/ansible-xml-beers.xml'
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: Add child element
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/beers
|
||||
add_children:
|
||||
- beer: "Окское"
|
||||
- beer: Окское
|
||||
register: add_children_elements_unicode
|
||||
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: results/test-add-children-elements-unicode.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
- name: Test expected result
|
||||
command: diff -u {{ role_path }}/results/test-add-children-elements-unicode.xml /tmp/ansible-xml-beers.xml
|
||||
assert:
|
||||
that:
|
||||
- add_children_elements_unicode.changed == true
|
||||
- comparison.changed == false # identical
|
||||
#command: diff -u {{ role_path }}/results/test-add-children-elements-unicode.xml /tmp/ansible-xml-beers.xml
|
||||
|
@ -1,15 +1,29 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: '{{ role_path }}/fixtures/ansible-xml-beers.xml'
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: Add child element
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/beers
|
||||
add_children:
|
||||
- beer: "Old Rasputin"
|
||||
- beer: Old Rasputin
|
||||
register: add_children_elements
|
||||
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: results/test-add-children-elements.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
- name: Test expected result
|
||||
command: diff -u {{ role_path }}/results/test-add-children-elements.xml /tmp/ansible-xml-beers.xml
|
||||
assert:
|
||||
that:
|
||||
- add_children_elements.changed == true
|
||||
- comparison.changed == false # identical
|
||||
#command: diff -u {{ role_path }}/results/test-add-children-elements.xml /tmp/ansible-xml-beers.xml
|
||||
|
@ -1,14 +1,28 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: '{{ role_path }}/fixtures/ansible-xml-beers.xml'
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: Add child element
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/beers
|
||||
add_children: "{{ bad_beers }}"
|
||||
add_children: '{{ bad_beers }}'
|
||||
register: add_children_from_groupvars
|
||||
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: results/test-add-children-from-groupvars.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
- name: Test expected result
|
||||
command: diff -u {{ role_path }}/results/test-add-children-from-groupvars.xml /tmp/ansible-xml-beers.xml
|
||||
assert:
|
||||
that:
|
||||
- add_children_from_groupvars.changed == true
|
||||
- comparison.changed == false # identical
|
||||
#command: diff -u {{ role_path }}/results/test-add-children-from-groupvars.xml /tmp/ansible-xml-beers.xml
|
||||
|
@ -1,17 +1,31 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: '{{ role_path }}/fixtures/ansible-xml-beers.xml'
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: Add child element
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/beers
|
||||
add_children:
|
||||
- beer:
|
||||
name: Окское
|
||||
type: экстра
|
||||
- beer:
|
||||
name: Окское
|
||||
type: экстра
|
||||
register: add_children_with_attributes_unicode
|
||||
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: results/test-add-children-with-attributes-unicode.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
- name: Test expected result
|
||||
command: diff -u {{ role_path }}/results/test-add-children-with-attributes-unicode.xml /tmp/ansible-xml-beers.xml
|
||||
assert:
|
||||
that:
|
||||
- add_children_with_attributes_unicode.changed == true
|
||||
- comparison.changed == false # identical
|
||||
#command: diff -u {{ role_path }}/results/test-add-children-with-attributes-unicode.xml /tmp/ansible-xml-beers.xml
|
||||
|
@ -1,22 +1,35 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: '{{ role_path }}/fixtures/ansible-xml-beers.xml'
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: Add child element
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/beers
|
||||
add_children:
|
||||
- beer:
|
||||
name: Ansible Brew
|
||||
type: light
|
||||
- beer:
|
||||
name: Ansible Brew
|
||||
type: light
|
||||
register: add_children_with_attributes
|
||||
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: results/test-add-children-with-attributes.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
# NOTE: This test may fail if lxml does not support predictable element attribute order
|
||||
# So we filter the failure out for these platforms (e.g. CentOS 6)
|
||||
# The module still works fine, we simply are not comparing as smart as we should.
|
||||
- name: Test expected result
|
||||
command: diff -u {{ role_path }}/results/test-add-children-with-attributes.xml /tmp/ansible-xml-beers.xml
|
||||
register: diff
|
||||
failed_when: diff.rc != 0 and lxml_predictable_attribute_order
|
||||
assert:
|
||||
that:
|
||||
- add_children_with_attributes.changed == true
|
||||
- comparison.changed == false # identical
|
||||
when: lxml_predictable_attribute_order
|
||||
#command: diff -u {{ role_path }}/results/test-add-children-with-attributes.xml /tmp/ansible-xml-beers.xml
|
||||
|
@ -1,16 +1,30 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: '{{ role_path }}/fixtures/ansible-xml-beers.xml'
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: Add child element with xml format
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/beers
|
||||
input_type: xml
|
||||
add_children:
|
||||
- "<beer>Old Rasputin</beer>"
|
||||
- '<beer>Old Rasputin</beer>'
|
||||
register: children_elements
|
||||
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: results/test-add-children-elements.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
check_mode: yes
|
||||
diff: yes·
|
||||
register: comparison
|
||||
|
||||
- name: Test expected result
|
||||
command: diff -u {{ role_path }}/results/test-add-children-elements.xml /tmp/ansible-xml-beers.xml
|
||||
assert:
|
||||
that:
|
||||
- children_elements.changed == true
|
||||
- comparison.changed == false # identical
|
||||
#command: diff -u {{ role_path }}/results/test-add-children-elements.xml /tmp/ansible-xml-beers.xml
|
||||
|
@ -1,13 +1,19 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: '{{ role_path }}/fixtures/ansible-xml-beers-unicode.xml'
|
||||
src: fixtures/ansible-xml-beers-unicode.xml
|
||||
dest: /tmp/ansible-xml-beers-unicode.xml
|
||||
|
||||
|
||||
- name: Count child element
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers-unicode.xml
|
||||
xpath: /business/beers/beer
|
||||
count: true
|
||||
count: yes
|
||||
register: beers
|
||||
failed_when: beers.count != 2
|
||||
|
||||
- name: Test expected result
|
||||
assert:
|
||||
that:
|
||||
- beers.changed == false
|
||||
- beers.count == 2
|
||||
|
@ -1,13 +1,19 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: '{{ role_path }}/fixtures/ansible-xml-beers.xml'
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: Add child element
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/beers/beer
|
||||
count: true
|
||||
count: yes
|
||||
register: beers
|
||||
failed_when: beers.count != 3
|
||||
|
||||
- name: Test expected result
|
||||
assert:
|
||||
that:
|
||||
- beers.changed == false
|
||||
- beers.count == 3
|
||||
|
@ -1,21 +1,32 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: '{{ role_path }}/fixtures/ansible-xml-beers-unicode.xml'
|
||||
src: fixtures/ansible-xml-beers-unicode.xml
|
||||
dest: /tmp/ansible-xml-beers-unicode.xml
|
||||
|
||||
|
||||
- name: Get element attributes
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers-unicode.xml
|
||||
xpath: /business/rating
|
||||
content: 'attribute'
|
||||
content: attribute
|
||||
register: get_element_attribute
|
||||
failed_when: get_element_attribute.matches[0]['rating'] is not defined or get_element_attribute.matches[0]['rating']['subjective'] != 'да'
|
||||
|
||||
- name: Test expected result
|
||||
assert:
|
||||
that:
|
||||
- get_element_attribute.changed == false
|
||||
- get_element_attribute.matches[0]['rating'] is defined and get_element_attribute.matches[0]['rating']['subjective'] == 'да'
|
||||
|
||||
- name: Get element text
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers-unicode.xml
|
||||
xpath: /business/rating
|
||||
content: 'text'
|
||||
content: text
|
||||
register: get_element_text
|
||||
failed_when: get_element_text.matches[0]['rating'] != 'десять'
|
||||
|
||||
- name: Test expected result
|
||||
assert:
|
||||
that:
|
||||
- get_element_text.changed == false
|
||||
- get_element_text.matches[0]['rating'] == 'десять'
|
||||
|
@ -1,21 +1,32 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: '{{ role_path }}/fixtures/ansible-xml-beers.xml'
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: Get element attributes
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/rating
|
||||
content: 'attribute'
|
||||
content: attribute
|
||||
register: get_element_attribute
|
||||
failed_when: get_element_attribute.matches[0]['rating'] is not defined or get_element_attribute.matches[0]['rating']['subjective'] != 'true'
|
||||
|
||||
- name: Test expected result
|
||||
assert:
|
||||
that:
|
||||
- get_element_attribute.changed == false
|
||||
- get_element_attribute.matches[0]['rating'] is defined and get_element_attribute.matches[0]['rating']['subjective'] == 'true'
|
||||
|
||||
- name: Get element text
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/rating
|
||||
content: 'text'
|
||||
content: text
|
||||
register: get_element_text
|
||||
failed_when: get_element_text.matches[0]['rating'] != '10'
|
||||
|
||||
- name: Test expected result
|
||||
assert:
|
||||
that:
|
||||
- get_element_text.changed == false
|
||||
- get_element_text.matches[0]['rating'] == '10'
|
||||
|
@ -1,15 +1,22 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: '{{ role_path }}/fixtures/ansible-xml-beers.xml'
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: Specify both children to add and a value
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
add_children:
|
||||
- child01
|
||||
- child02
|
||||
- child01
|
||||
- child02
|
||||
value: conflict!
|
||||
register: module_output
|
||||
failed_when: "module_output.failed == 'false'"
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Test expected result
|
||||
assert:
|
||||
that:
|
||||
- module_output.changed == false
|
||||
- module_output.failed == true
|
||||
|
@ -1,16 +1,30 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: '{{ role_path }}/fixtures/ansible-xml-beers.xml'
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: Pretty print
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/beers
|
||||
pretty_print: True
|
||||
pretty_print: yes
|
||||
add_children:
|
||||
- beer: "Old Rasputin"
|
||||
- beer: Old Rasputin
|
||||
register: pretty_print
|
||||
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: results/test-pretty-print.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
- name: Test expected result
|
||||
command: diff -u {{ role_path }}/results/test-pretty-print.xml /tmp/ansible-xml-beers.xml
|
||||
assert:
|
||||
that:
|
||||
- pretty_print.changed == true
|
||||
- comparison.changed == false # identical
|
||||
#command: diff -u {{ role_path }}/results/test-pretty-print.xml /tmp/ansible-xml-beers.xml
|
||||
|
@ -1,14 +1,28 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: '{{ role_path }}/fixtures/ansible-xml-beers.xml'
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: Remove '/business/rating/@subjective'
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/rating/@subjective
|
||||
ensure: absent
|
||||
state: absent
|
||||
register: remove_attribute
|
||||
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: results/test-remove-attribute.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
- name: Test expected result
|
||||
command: diff -u {{ role_path }}/results/test-remove-attribute.xml /tmp/ansible-xml-beers.xml
|
||||
assert:
|
||||
that:
|
||||
- remove_attribute.changed == true
|
||||
- comparison.changed == false # identical
|
||||
#command: diff -u {{ role_path }}/results/test-remove-attribute.xml /tmp/ansible-xml-beers.xml
|
||||
|
@ -1,14 +1,28 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: '{{ role_path }}/fixtures/ansible-xml-beers.xml'
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: Remove '/business/rating'
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/rating
|
||||
ensure: absent
|
||||
state: absent
|
||||
register: remove_element
|
||||
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: results/test-remove-element.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
- name: Test expected result
|
||||
command: diff -u {{ role_path }}/results/test-remove-element.xml /tmp/ansible-xml-beers.xml
|
||||
assert:
|
||||
that:
|
||||
- remove_element.changed == true
|
||||
- comparison.changed == false # identical
|
||||
#command: diff -u {{ role_path }}/results/test-remove-element.xml /tmp/ansible-xml-beers.xml
|
||||
|
@ -1,16 +1,29 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: '{{ role_path }}/fixtures/ansible-xml-beers.xml'
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: Set '/business/rating/@subjective' to 'нет'
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/rating
|
||||
attribute: subjective
|
||||
value: "нет"
|
||||
value: нет
|
||||
register: set_attribute_value_unicode
|
||||
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: results/test-set-attribute-value-unicode.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
- name: Test expected result
|
||||
command: diff -u {{ role_path }}/results/test-set-attribute-value-unicode.xml /tmp/ansible-xml-beers.xml
|
||||
changed_when: False
|
||||
assert:
|
||||
that:
|
||||
- set_attribute_value_unicode.changed == true
|
||||
- comparison.changed == false # identical
|
||||
#command: diff -u {{ role_path }}/results/test-set-attribute-value-unicode.xml /tmp/ansible-xml-beers.xml
|
||||
|
@ -1,16 +1,29 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: '{{ role_path }}/fixtures/ansible-xml-beers.xml'
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: Set '/business/rating/@subjective' to 'false'
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/rating
|
||||
attribute: subjective
|
||||
value: "false"
|
||||
value: 'false'
|
||||
register: set_attribute_value
|
||||
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: results/test-set-attribute-value.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
- name: Test expected result
|
||||
command: diff -u {{ role_path }}/results/test-set-attribute-value.xml /tmp/ansible-xml-beers.xml
|
||||
changed_when: False
|
||||
assert:
|
||||
that:
|
||||
- set_attribute_value.changed == true
|
||||
- comparison.changed == false # identical
|
||||
#command: diff -u {{ role_path }}/results/test-set-attribute-value.xml /tmp/ansible-xml-beers.xml
|
||||
|
@ -1,27 +1,46 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
command: cp {{ role_path }}/fixtures/ansible-xml-beers.xml /tmp/ansible-xml-beers.xml
|
||||
copy:
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: Set child elements
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/beers
|
||||
set_children:
|
||||
- beer: "Окское"
|
||||
- beer: "Невское"
|
||||
set_children: &children
|
||||
- beer: Окское
|
||||
- beer: Невское
|
||||
register: set_children_elements_unicode
|
||||
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: results/test-set-children-elements-unicode.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
- name: Test expected result
|
||||
command: diff -u {{ role_path }}/results/test-set-children-elements-unicode.xml /tmp/ansible-xml-beers.xml
|
||||
assert:
|
||||
that:
|
||||
- set_children_elements_unicode.changed == true
|
||||
- comparison.changed == false # identical
|
||||
#command: diff -u {{ role_path }}/results/test-set-children-elements-unicode.xml /tmp/ansible-xml-beers.xml
|
||||
|
||||
- name: Set child elements
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/beers
|
||||
set_children:
|
||||
- beer: "Окское"
|
||||
- beer: "Невское"
|
||||
register: set_children_again
|
||||
|
||||
- fail:
|
||||
msg: "Setting children is not idempotent!"
|
||||
when: set_children_again.changed
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: results/test-set-children-elements-unicode.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
- name: Test expected result
|
||||
assert:
|
||||
that:
|
||||
- set_children_again.changed == false
|
||||
- comparison.changed == false # identical
|
||||
#command: diff -u {{ role_path }}/results/test-set-children-elements-unicode.xml /tmp/ansible-xml-beers.xml
|
||||
|
@ -1,27 +1,53 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
command: cp {{ role_path }}/fixtures/ansible-xml-beers.xml /tmp/ansible-xml-beers.xml
|
||||
copy:
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: Set child elements
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/beers
|
||||
set_children:
|
||||
- beer: "90 Minute IPA"
|
||||
- beer: "Harvest Pumpkin Ale"
|
||||
set_children: &children
|
||||
- beer: 90 Minute IPA
|
||||
- beer: Harvest Pumpkin Ale
|
||||
register: set_children_elements
|
||||
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: results/test-set-children-elements.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
- name: Test expected result
|
||||
command: diff -u {{ role_path }}/results/test-set-children-elements.xml /tmp/ansible-xml-beers.xml
|
||||
assert:
|
||||
that:
|
||||
- set_children_elements.changed == true
|
||||
- comparison.changed == false # identical
|
||||
#command: diff -u {{ role_path }}/results/test-set-children-elements.xml /tmp/ansible-xml-beers.xml
|
||||
|
||||
- name: Set child elements
|
||||
|
||||
- name: Set child elements (again)
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/beers
|
||||
set_children:
|
||||
- beer: "90 Minute IPA"
|
||||
- beer: "Harvest Pumpkin Ale"
|
||||
set_children: *children
|
||||
register: set_children_again
|
||||
|
||||
- fail:
|
||||
msg: "Setting children is not idempotent!"
|
||||
when: set_children_again.changed
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: results/test-set-children-elements.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
- name: Test expected result
|
||||
assert:
|
||||
that:
|
||||
- set_children_again.changed == false
|
||||
- comparison.changed == false # identical
|
||||
#command: diff -u {{ role_path }}/results/test-set-children-elements.xml /tmp/ansible-xml-beers.xml
|
||||
|
@ -1,14 +1,28 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: '{{ role_path }}/fixtures/ansible-xml-beers.xml'
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
- name: Set /business/website/address to empty string.
|
||||
|
||||
- name: Set '/business/website/address' to empty string.
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/website/address
|
||||
value: ''
|
||||
register: set_element_value_empty
|
||||
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: results/test-set-element-value-empty.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
- name: Test expected result
|
||||
command: diff -u {{ role_path }}/results/test-set-element-value-empty.xml /tmp/ansible-xml-beers.xml
|
||||
assert:
|
||||
that:
|
||||
- set_element_value_empty.changed == true
|
||||
- comparison.changed == false # identical
|
||||
#command: diff -u {{ role_path }}/results/test-set-element-value-empty.xml /tmp/ansible-xml-beers.xml
|
||||
|
@ -1,37 +1,43 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: '{{ role_path }}/fixtures/ansible-xml-beers.xml'
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: Add 2nd '/business/rating' with value 'пять'
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business
|
||||
add_children:
|
||||
- rating: "пять"
|
||||
- rating: пять
|
||||
|
||||
- name: Set '/business/rating' to 'пять'
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/rating
|
||||
value: "пять"
|
||||
value: пять
|
||||
register: set_element_first_run
|
||||
|
||||
- name: Set '/business/rating' to 'false'... again
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/rating
|
||||
value: "пять"
|
||||
value: пять
|
||||
register: set_element_second_run
|
||||
|
||||
- name: Test expected result
|
||||
command: diff -u {{ role_path }}/results/test-set-element-value-unicode.xml /tmp/ansible-xml-beers.xml
|
||||
changed_when: no
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: results/test-set-element-value-unicode.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
- name: Test registered 'changed' on run 1 and unchanged on run 2
|
||||
- name: Test expected result
|
||||
assert:
|
||||
that:
|
||||
- set_element_first_run.changed
|
||||
- not set_element_second_run.changed
|
||||
...
|
||||
- set_element_first_run.changed == true
|
||||
- set_element_second_run.changed == false
|
||||
- comparison.changed == false # identical
|
||||
#command: diff -u {{ role_path }}/results/test-set-element-value-unicode.xml /tmp/ansible-xml-beers.xml
|
||||
|
@ -1,37 +1,43 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: '{{ role_path }}/fixtures/ansible-xml-beers.xml'
|
||||
src: fixtures/ansible-xml-beers.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
- name: Add 2nd '/business/rating' with value '5'
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business
|
||||
add_children:
|
||||
- rating: "5"
|
||||
- rating: '5'
|
||||
|
||||
- name: Set '/business/rating' to '5'
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/rating
|
||||
value: "5"
|
||||
value: '5'
|
||||
register: set_element_first_run
|
||||
|
||||
- name: Set '/business/rating' to 'false'... again
|
||||
- name: Set '/business/rating' to '5'... again
|
||||
xml:
|
||||
path: /tmp/ansible-xml-beers.xml
|
||||
xpath: /business/rating
|
||||
value: "5"
|
||||
value: '5'
|
||||
register: set_element_second_run
|
||||
|
||||
- name: Test expected result
|
||||
command: diff -u {{ role_path }}/results/test-set-element-value.xml /tmp/ansible-xml-beers.xml
|
||||
changed_when: no
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: results/test-set-element-value.xml
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
- name: Test registered 'changed' on run 1 and unchanged on run 2
|
||||
- name: Test expected result
|
||||
assert:
|
||||
that:
|
||||
- set_element_first_run.changed
|
||||
- not set_element_second_run.changed
|
||||
...
|
||||
- set_element_first_run.changed == true
|
||||
- set_element_second_run.changed == false
|
||||
- comparison.changed == false # identical
|
||||
#command: diff -u {{ role_path }}/results/test-set-element-value.xml /tmp/ansible-xml-beers.xml
|
||||
|
@ -0,0 +1,54 @@
|
||||
---
|
||||
- name: Setup test fixture
|
||||
copy:
|
||||
src: fixtures/ansible-xml-namespaced-beers.xml
|
||||
dest: /tmp/ansible-xml-namespaced-beers-xml.xml
|
||||
|
||||
- name: Set child elements
|
||||
xml:
|
||||
path: /tmp/ansible-xml-namespaced-beers-xml.xml
|
||||
xpath: /bus:business/ber:beers
|
||||
namespaces:
|
||||
bus: http://test.business
|
||||
ber: http://test.beers
|
||||
set_children:
|
||||
- beer: 90 Minute IPA
|
||||
- beer: Harvest Pumpkin Ale
|
||||
|
||||
- name: Copy state after first set_children
|
||||
copy:
|
||||
src: /tmp/ansible-xml-namespaced-beers.xml
|
||||
dest: /tmp/ansible-xml-namespaced-beers-1.xml
|
||||
|
||||
- name: Set child elements again
|
||||
xml:
|
||||
path: /tmp/ansible-xml-namespaced-beers-xml.xml
|
||||
xpath: /bus:business/ber:beers
|
||||
namespaces:
|
||||
bus: http://test.business
|
||||
ber: http://test.beers
|
||||
set_children:
|
||||
- beer: 90 Minute IPA
|
||||
- beer: Harvest Pumpkin Ale
|
||||
register: set_children_again
|
||||
|
||||
- name: Copy state after second set_children
|
||||
copy:
|
||||
src: /tmp/ansible-xml-namespaced-beers.xml
|
||||
dest: /tmp/ansible-xml-namespaced-beers-2.xml
|
||||
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
src: /tmp/ansible-xml-namespaced-beers-1.xml
|
||||
dest: /tmp/ansible-xml-namespaced-beers-2.xml
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
#command: diff /tmp/ansible-xml-namespaced-beers-1.xml /tmp/ansible-xml-namespaced-beers-2.xml
|
||||
|
||||
- name: Test expected result
|
||||
assert:
|
||||
that:
|
||||
- set_children_again.changed == false # idempotency
|
||||
- set_namespaced_attribute_value.changed == true
|
||||
- comparison.changed == false # identical
|
@ -1,31 +1,74 @@
|
||||
---
|
||||
- name: Read from xmlstring
|
||||
# NOTE: Jinja2 templating eats trailing newlines
|
||||
- name: Read from xmlstring (not using pretty_print)
|
||||
xml:
|
||||
xmlstring: "{{ lookup('file', '{{ role_path }}/fixtures/ansible-xml-beers.xml') }}"
|
||||
xpath: .
|
||||
register: xmlresponse
|
||||
|
||||
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
content: "{{ xmlresponse.xmlstring }}\n"
|
||||
dest: '{{ role_path }}/results/test-pretty-print-only.xml'
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
- name: Test expected result
|
||||
assert:
|
||||
that:
|
||||
- xmlresponse.changed == false
|
||||
- comparison.changed == false # identical
|
||||
#command: diff -u {{ role_path }}/results/test-pretty-print-only.xml /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
# NOTE: Jinja2 templating eats trailing newlines
|
||||
- name: Read from xmlstring (using pretty_print)
|
||||
xml:
|
||||
xmlstring: "{{ lookup('file', '{{ role_path }}/fixtures/ansible-xml-beers.xml') }}"
|
||||
pretty_print: True
|
||||
pretty_print: yes
|
||||
register: xmlresponse
|
||||
|
||||
- name: Write result to file
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
content: "{{ xmlresponse.xmlstring }}"
|
||||
content: '{{ xmlresponse.xmlstring }}'
|
||||
dest: '{{ role_path }}/results/test-pretty-print-only.xml'
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
# FIXME: This change is related to the newline added by pretty_print
|
||||
- name: Test expected result
|
||||
command: diff -u {{ role_path }}/results/test-pretty-print-only.xml /tmp/ansible-xml-beers.xml
|
||||
assert:
|
||||
that:
|
||||
- xmlresponse.changed == true
|
||||
- comparison.changed == false # identical
|
||||
#command: diff -u {{ role_path }}/results/test-pretty-print-only.xml /tmp/ansible-xml-beers.xml
|
||||
|
||||
|
||||
# NOTE: Jinja2 templating eats trailing newlines
|
||||
- name: Read from xmlstring
|
||||
xml:
|
||||
xmlstring: "{{ lookup('file', '{{ role_path }}/fixtures/ansible-xml-beers.xml') }}"
|
||||
xpath: /business/beers
|
||||
pretty_print: True
|
||||
pretty_print: yes
|
||||
add_children:
|
||||
- beer: "Old Rasputin"
|
||||
- beer: Old Rasputin
|
||||
register: xmlresponse_modification
|
||||
|
||||
- name: Write result to file
|
||||
- name: Compare to expected result
|
||||
copy:
|
||||
dest: /tmp/ansible-xml-beers.xml
|
||||
content: "{{ xmlresponse_modification.xmlstring }}"
|
||||
content: '{{ xmlresponse_modification.xmlstring }}'
|
||||
dest: '{{ role_path }}/results/test-pretty-print.xml'
|
||||
check_mode: yes
|
||||
diff: yes
|
||||
register: comparison
|
||||
|
||||
# FIXME: This change is related to the newline added by pretty_print
|
||||
- name: Test expected result
|
||||
command: diff -u {{ role_path }}/results/test-pretty-print.xml /tmp/ansible-xml-beers.xml
|
||||
assert:
|
||||
that:
|
||||
- xmlresponse_modification.changed == true
|
||||
- comparison.changed == false # identical
|
||||
#command: diff -u {{ role_path }}/results/test-pretty-print.xml /tmp/ansible-xml-beers.xml
|
||||
|
Loading…
Reference in New Issue