Skip to content

Commit 7dbfe36

Browse files
committed
Fix remaining issues with test examples
This PR includes: - Replaced the "ensure" parameter with "state" - Replaced the "file" parameter with "path" - Use "yes" and "no" as booleans, instead of "true", "True", "false" and "False" - Use YAML syntax everywhere - Avoid the use of quotes when they are not needed
1 parent 61c98da commit 7dbfe36

18 files changed

+111
-62
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Remove the ``subjective`` attribute of the rating element:
6666
xml:
6767
path: /foo/bar.xml
6868
xpath: /business/rating/@subjective
69-
ensure: absent
69+
state: absent
7070
```
7171
7272
Set the rating to **11**
@@ -84,7 +84,7 @@ Get count of beers nodes
8484
xml:
8585
path: /foo/bar.xml
8686
xpath: /business/beers/beer
87-
count: true
87+
count: yes
8888
register: hits
8989

9090
debug:
@@ -135,7 +135,7 @@ xml:
135135
```
136136
137137
Add a ``validxhtml`` element to the ``website`` element. Note that
138-
``ensure`` is ``present`` by default, and ``value`` defaults to
138+
``state`` is ``present`` by default, and ``value`` defaults to
139139
``null`` for elements. The result is something like
140140
``<website><validxhtml />...</website>``
141141
@@ -162,7 +162,7 @@ xml:
162162
xml:
163163
path: /foo/bar.xml
164164
xpath: /business/website/*
165-
ensure: absent
165+
state: absent
166166
```
167167
168168
(2/2) Remove all children from the website element:
@@ -180,7 +180,7 @@ What happens if you say:
180180
181181
```yaml
182182
xml:
183-
file: /foo/bar.xml
183+
path: /foo/bar.xml
184184
xpath: /beers
185185
```
186186

tests/test-add-element-implicitly.yml

Lines changed: 81 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,101 @@
11
---
22
- name: Setup test fixture
3-
copy: src=fixtures/ansible-xml-beers.xml dest=/tmp/ansible-xml-beers-implicit.xml
3+
copy:
4+
src: fixtures/ansible-xml-beers.xml
5+
dest: /tmp/ansible-xml-beers-implicit.xml
46

57
- name: Add a phonenumber element to the business element. Implicit mkdir -p behavior where applicable
6-
xml: file=/tmp/ansible-xml-beers-implicit.xml xpath=/business/phonenumber value=555-555-1234
8+
xml:
9+
path: /tmp/ansible-xml-beers-implicit.xml
10+
xpath: /business/phonenumber
11+
value: 555-555-1234
712

813
- name: Add a owner element to the business element, testing implicit mkdir -p behavior 1/2
9-
xml: file=/tmp/ansible-xml-beers-implicit.xml xpath=/business/owner/name/last value=Smith
14+
xml:
15+
path: /tmp/ansible-xml-beers-implicit.xml
16+
xpath: /business/owner/name/last
17+
value: Smith
1018

1119
- name: Add a owner element to the business element, testing implicit mkdir -p behavior 2/2
12-
xml: file=/tmp/ansible-xml-beers-implicit.xml xpath=/business/owner/name/first value=John
20+
xml:
21+
path: /tmp/ansible-xml-beers-implicit.xml
22+
xpath: /business/owner/name/first
23+
value: John
1324

1425
- name: Add a validxhtml element to the website element. Note that ensure is present by default and while value defaults to null for elements, if one doesn't specify it we don't know what to do.
15-
xml: file=/tmp/ansible-xml-beers-implicit.xml xpath=/business/website/validxhtml
26+
xml:
27+
path: /tmp/ansible-xml-beers-implicit.xml
28+
xpath: /business/website/validxhtml
1629

1730
- name: Add an empty validateon attribute to the validxhtml element. This actually makes the previous example redundant because of the implicit parent-node creation behavior.
18-
xml: file=/tmp/ansible-xml-beers-implicit.xml xpath=/business/website/validxhtml/@validateon
31+
xml:
32+
path: /tmp/ansible-xml-beers-implicit.xml
33+
xpath: /business/website/validxhtml/@validateon
1934

2035
- name: Add an empty validateon attribute to the validxhtml element. Actually verifies the implicit parent-node creation behavior.
21-
xml: file=/tmp/ansible-xml-beers-implicit.xml xpath=/business/website_bis/validxhtml/@validateon
36+
xml:
37+
path: /tmp/ansible-xml-beers-implicit.xml
38+
xpath: /business/website_bis/validxhtml/@validateon
2239

2340
- name: Add an attribute with a value
24-
xml: file=/tmp/ansible-xml-beers-implicit.xml xpath=/business/owner/@dob='1976-04-12'
41+
xml:
42+
path: /tmp/ansible-xml-beers-implicit.xml
43+
xpath: /business/owner/@dob='1976-04-12'
2544

2645
- name: Add an element with a value, alternate syntax
27-
xml: file=/tmp/ansible-xml-beers-implicit.xml xpath="/business/beers/beer/text()=\"George Killian's Irish Red\"" # note the quote within an XPath string thing
46+
xml:
47+
path: /tmp/ansible-xml-beers-implicit.xml
48+
# note the quote within an XPath string thing
49+
xpath: /business/beers/beer/text()="George Killian's Irish Red"
2850

2951
- name: Add an element without special characters
30-
xml: file=/tmp/ansible-xml-beers-implicit.xml xpath=/business/testnormalelement value="xml tag with no special characters" pretty_print=true
52+
xml:
53+
file: /tmp/ansible-xml-beers-implicit.xml
54+
xpath: /business/testnormalelement
55+
value: xml tag with no special characters
56+
pretty_print: yes
3157

3258
- name: Add an element with dash
33-
xml: file=/tmp/ansible-xml-beers-implicit.xml xpath=/business/test-with-dash value="xml tag with dashes" pretty_print=true
59+
xml:
60+
file: /tmp/ansible-xml-beers-implicit.xml
61+
xpath: /business/test-with-dash
62+
value: xml tag with dashes
63+
pretty_print: yes
3464

3565
- name: Add an element with dot
36-
xml: file=/tmp/ansible-xml-beers-implicit.xml xpath=/business/test-with-dash.and.dot value="xml tag with dashes and dots" pretty_print=true
66+
xml:
67+
file: /tmp/ansible-xml-beers-implicit.xml
68+
xpath: /business/test-with-dash.and.dot
69+
value: xml tag with dashes and dots
70+
pretty_print: yes
3771

3872
- name: Add an element with underscore
39-
xml: file=/tmp/ansible-xml-beers-implicit.xml xpath=/business/test-with.dash_and.dot_and-underscores value="xml tag with dashes, dots and underscores" pretty_print=true
73+
xml:
74+
file: /tmp/ansible-xml-beers-implicit.xml
75+
xpath: /business/test-with.dash_and.dot_and-underscores
76+
value: xml tag with dashes, dots and underscores
77+
pretty_print: yes
4078

4179
- name: Add an attribute on a conditional element
42-
xml: file=/tmp/ansible-xml-beers-implicit.xml xpath="/business/beers/beer[text()=\"George Killian's Irish Red\"]/@color='red'"
80+
xml:
81+
path: /tmp/ansible-xml-beers-implicit.xml
82+
xpath: /business/beers/beer[text()="George Killian's Irish Red"]/@color='red'
4383

4484
- name: Add two attributes on a conditional element
45-
xml: file=/tmp/ansible-xml-beers-implicit.xml xpath="/business/beers/beer[text()=\"Pilsner Urquell\" and @origin='CZ']/@color='blonde'"
85+
xml:
86+
path: /tmp/ansible-xml-beers-implicit.xml
87+
xpath: /business/beers/beer[text()="Pilsner Urquell" and @origin='CZ']/@color='blonde'
4688

4789
- name: Add a owner element to the business element, testing implicit mkdir -p behavior 3/2 -- complex lookup
48-
xml: file=/tmp/ansible-xml-beers-implicit.xml xpath=/business/owner/name[first/text()='John']/middle value=Q
90+
xml:
91+
path: /tmp/ansible-xml-beers-implicit.xml
92+
xpath: /business/owner/name[first/text()='John']/middle
93+
value: Q
4994

5095
- name: Pretty Print this!
51-
xml: file=/tmp/ansible-xml-beers-implicit.xml pretty_print=True
96+
xml:
97+
path: /tmp/ansible-xml-beers-implicit.xml
98+
pretty_print: yes
5299

53100
- name: Test expected result
54101
command: diff -u results/test-add-element-implicitly.yml /tmp/ansible-xml-beers-implicit.xml
@@ -59,80 +106,80 @@
59106

60107
- name: Add a phonenumber element to the business element. Implicit mkdir -p behavior where applicable
61108
xml:
62-
file: /tmp/ansible-xml-beers-implicit.xml
109+
path: /tmp/ansible-xml-beers-implicit.xml
63110
xpath: /business/a:phonenumber
64111
value: 555-555-1234
65112
namespaces:
66113
a: http://example.com/some/namespace
67114

68115
- name: Add a owner element to the business element, testing implicit mkdir -p behavior 1/2
69116
xml:
70-
file: /tmp/ansible-xml-beers-implicit.xml
117+
path: /tmp/ansible-xml-beers-implicit.xml
71118
xpath: /business/a:owner/a:name/a:last
72119
value: Smith
73120
namespaces:
74121
a: http://example.com/some/namespace
75122

76123
- name: Add a owner element to the business element, testing implicit mkdir -p behavior 2/2
77124
xml:
78-
file: /tmp/ansible-xml-beers-implicit.xml
125+
path: /tmp/ansible-xml-beers-implicit.xml
79126
xpath: /business/a:owner/a:name/a:first
80127
value: John
81128
namespaces:
82129
a: http://example.com/some/namespace
83130

84131
- name: Add a validxhtml element to the website element. Note that ensure is present by default and while value defaults to null for elements, if one doesn't specify it we don't know what to do.
85132
xml:
86-
file: /tmp/ansible-xml-beers-implicit.xml
133+
path: /tmp/ansible-xml-beers-implicit.xml
87134
xpath: /business/a:website/a:validxhtml
88135
namespaces:
89136
a: http://example.com/some/namespace
90137

91138
- name: Add an empty validateon attribute to the validxhtml element. This actually makes the previous example redundant because of the implicit parent-node creation behavior.
92139
xml:
93-
file: /tmp/ansible-xml-beers-implicit.xml
140+
path: /tmp/ansible-xml-beers-implicit.xml
94141
xpath: /business/a:website/a:validxhtml/@a:validateon
95142
namespaces:
96143
a: http://example.com/some/namespace
97144

98145
- name: Add an empty validateon attribute to the validxhtml element. Actually verifies the implicit parent-node creation behavior.
99146
xml:
100-
file: /tmp/ansible-xml-beers-implicit.xml
147+
path: /tmp/ansible-xml-beers-implicit.xml
101148
xpath: /business/a:website_bis/a:validxhtml/@a:validateon
102149
namespaces:
103150
a: http://example.com/some/namespace
104151

105152
- name: Add an attribute with a value
106153
xml:
107-
file: /tmp/ansible-xml-beers-implicit.xml
154+
path: /tmp/ansible-xml-beers-implicit.xml
108155
xpath: /business/a:owner/@a:dob='1976-04-12'
109156
namespaces:
110157
a: http://example.com/some/namespace
111158

112159
- name: Add an element with a value, alternate syntax
113160
xml:
114-
file: /tmp/ansible-xml-beers-implicit.xml
115-
xpath: "/business/a:beers/a:beer/text()=\"George Killian's Irish Red\"" # note the quote within an XPath string thing
161+
path: /tmp/ansible-xml-beers-implicit.xml
162+
xpath: /business/a:beers/a:beer/text()="George Killian's Irish Red" # note the quote within an XPath string thing
116163
namespaces:
117164
a: http://example.com/some/namespace
118165

119166
- name: Add an attribute on a conditional element
120167
xml:
121-
file: /tmp/ansible-xml-beers-implicit.xml
122-
xpath: "/business/a:beers/a:beer[text()=\"George Killian's Irish Red\"]/@a:color='red'"
168+
path: /tmp/ansible-xml-beers-implicit.xml
169+
xpath: /business/a:beers/a:beer[text()="George Killian's Irish Red"]/@a:color='red'
123170
namespaces:
124171
a: http://example.com/some/namespace
125172

126173
- name: Add two attributes on a conditional element
127174
xml:
128-
file: /tmp/ansible-xml-beers-implicit.xml
129-
xpath: "/business/a:beers/a:beer[text()=\"Pilsner Urquell\" and @a:origin='CZ']/@a:color='blonde'"
175+
path: /tmp/ansible-xml-beers-implicit.xml
176+
xpath: /business/a:beers/a:beer[text()="Pilsner Urquell" and @a:origin='CZ']/@a:color='blonde'
130177
namespaces:
131178
a: http://example.com/some/namespace
132179

133180
- name: Add a owner element to the business element, testing implicit mkdir -p behavior 3/2 -- complex lookup
134181
xml:
135-
file: /tmp/ansible-xml-beers-implicit.xml
182+
path: /tmp/ansible-xml-beers-implicit.xml
136183
xpath: /business/a:owner/a:name[a:first/text()='John']/a:middle
137184
value: Q
138185
namespaces:
@@ -176,4 +223,6 @@
176223
a: http://example.com/some/namespace
177224

178225
- name: Pretty Print this!
179-
xml: file=/tmp/ansible-xml-beers-implicit.xml pretty_print=True
226+
xml:
227+
path: /tmp/ansible-xml-beers-implicit.xml
228+
pretty_print: yes

tests/test-count-unicode.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
xml:
99
path: /tmp/ansible-xml-beers-unicode.xml
1010
xpath: /business/beers/beer
11-
count: true
11+
count: yes
1212
register: beers
1313
failed_when: beers.count != 2

tests/test-count.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
xml:
99
path: /tmp/ansible-xml-beers.xml
1010
xpath: /business/beers/beer
11-
count: true
11+
count: yes
1212
register: beers
13-
failed_when: beers.count != 3
13+
failed_when: beers.count != 3

tests/test-mutually-exclusive-attributes.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
- child02
1313
value: conflict!
1414
register: module_output
15-
failed_when: "module_output.failed == 'false'"
15+
failed_when: module_output.failed == 'false'

tests/test-pretty-print-only.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
- name: Setup test fixture
3-
shell: cat fixtures/ansible-xml-beers.xml | sed 's/^[ ]*//g' > /tmp/ansible-xml-beers.xml
3+
shell: sed 's/^[ ]*//g' <fixtures/ansible-xml-beers.xml >/tmp/ansible-xml-beers.xml
44

55
- name: Pretty print without modification
66
xml:
77
path: /tmp/ansible-xml-beers.xml
8-
pretty_print: True
8+
pretty_print: yes
99

1010
- name: Test expected result
11-
command: diff results/test-pretty-print-only.xml /tmp/ansible-xml-beers.xml
11+
command: diff results/test-pretty-print-only.xml /tmp/ansible-xml-beers.xml

tests/test-pretty-print.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
xml:
99
path: /tmp/ansible-xml-beers.xml
1010
xpath: /business/beers
11-
pretty_print: True
11+
pretty_print: yes
1212
add_children:
1313
- beer: "Old Rasputin"
1414

1515
- name: Test expected result
16-
command: diff results/test-pretty-print.xml /tmp/ansible-xml-beers.xml
16+
command: diff results/test-pretty-print.xml /tmp/ansible-xml-beers.xml

tests/test-remove-attribute.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
xml:
99
path: /tmp/ansible-xml-beers.xml
1010
xpath: /business/rating/@subjective
11-
ensure: absent
11+
state: absent
1212

1313
- name: Test expected result
14-
command: diff results/test-remove-attribute.xml /tmp/ansible-xml-beers.xml
14+
command: diff results/test-remove-attribute.xml /tmp/ansible-xml-beers.xml

tests/test-remove-element.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
xml:
99
path: /tmp/ansible-xml-beers.xml
1010
xpath: /business/rating
11-
ensure: absent
11+
state: absent
1212

1313
- name: Test expected result
14-
command: diff results/test-remove-element.xml /tmp/ansible-xml-beers.xml
14+
command: diff results/test-remove-element.xml /tmp/ansible-xml-beers.xml

tests/test-remove-namespaced-attribute.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
ber: http://test.beers
1414
rat: http://test.rating
1515
attr: http://test.attribute
16-
ensure: absent
16+
state: absent
1717

1818
- name: Test expected result
19-
command: diff results/test-remove-namespaced-attribute.xml /tmp/ansible-xml-namespaced-beers.xml
19+
command: diff results/test-remove-namespaced-attribute.xml /tmp/ansible-xml-namespaced-beers.xml

0 commit comments

Comments
 (0)