Bump to 1.14.1
[platform/upstream/augeas.git] / tests / xpath.tests
1 # Tests of the XPath matching
2
3 # Blank lines and lines starting with '#' are ignored
4 #
5 # Each test consists of one line declaring the test followed by a complete
6 # list of the expected result of the match.
7 #
8 # The test is declared with a line 'test NAME MATCH'. A result is either
9 # just a path (meaning that the value associated with that node must be
10 # NULL) or of the form PATH = VALUE, meaning that the value for the node at
11 # PATH must be VALUE. If VALUE is '...', the test does not check the value
12 # associated with PATH in the tree.
13 #
14 # The MATCH XPath expression is matched against a fixed tree (the one from the
15 # root/ subdirectory) and the result of the aug_match is compared with the
16 # results listed in the test
17 #
18 # The test framework sets up variables:
19 #   hosts      /files/etc/hosts/*
20 #   localhost  '127.0.0.1'
21 #   php        /files/etc/php.ini
22
23 # Very simple to warm up
24 test wildcard /files/etc/hosts/*/ipaddr
25      /files/etc/hosts/1/ipaddr = 127.0.0.1
26      /files/etc/hosts/2/ipaddr = 172.31.122.14
27
28 test wildcard-var $hosts/ipaddr
29      /files/etc/hosts/1/ipaddr = 127.0.0.1
30      /files/etc/hosts/2/ipaddr = 172.31.122.14
31
32 # Compare the value of the current node with a constant
33 test self-value /files/etc/hosts/*/ipaddr[ . = '127.0.0.1' ]
34      /files/etc/hosts/1/ipaddr = 127.0.0.1
35
36 test self-value-var $hosts/ipaddr[ . = $localhost ]
37      /files/etc/hosts/1/ipaddr = 127.0.0.1
38
39 # Find nodes that have a child named 'ipaddr' with a fixed value
40 test child-value /files/etc/hosts/*[ipaddr = '127.0.0.1']
41      /files/etc/hosts/1
42
43 test child-value-var $hosts[ipaddr = $localhost]
44      /files/etc/hosts/1
45
46 # Find nodes that have a child 'ipaddr' that has no value
47 test child-nil-value /files/etc/hosts/*[ipaddr = '']
48
49 test child-nil-value-var $hosts[ipaddr = '']
50
51 # Find nodes that have no value
52 test self-nil-value /files/etc/hosts/*[. = '']
53      /files/etc/hosts/1
54      /files/etc/hosts/2
55
56 test self-nil-value-var $hosts[. = '']
57      /files/etc/hosts/1
58      /files/etc/hosts/2
59
60 # Match over two levels of the tree
61 test two-wildcards /files/etc/*/*[ipaddr='127.0.0.1']
62      /files/etc/hosts/1
63
64 test pam-system-auth /files/etc/pam.d/*/*[module = 'system-auth']
65      /files/etc/pam.d/login/2
66      /files/etc/pam.d/login/4
67      /files/etc/pam.d/login/5
68      /files/etc/pam.d/login/8
69      /files/etc/pam.d/postgresql/1
70      /files/etc/pam.d/postgresql/2
71      /files/etc/pam.d/newrole/1
72      /files/etc/pam.d/newrole/2
73      /files/etc/pam.d/newrole/3
74
75 # Multiple predicates are treated with 'and'
76 test pam-two-preds /files/etc/pam.d/*/*[module = 'system-auth'][type = 'account']
77      /files/etc/pam.d/login/4
78      /files/etc/pam.d/postgresql/2
79      /files/etc/pam.d/newrole/2
80
81 # Find nodes that have siblings with a given value
82 test pam-two-preds-control /files/etc/pam.d/*/*[module = 'system-auth'][type = 'account']/control
83      /files/etc/pam.d/login/4/control = include
84      /files/etc/pam.d/postgresql/2/control = include
85      /files/etc/pam.d/newrole/2/control = include
86
87 # last() gives the last node with a certain name
88 test last /files/etc/hosts/*[ipaddr = "127.0.0.1"]/alias[last()]
89      /files/etc/hosts/1/alias[3] = galia
90
91 test last-var $hosts[ipaddr = $localhost]/alias[last()]
92      /files/etc/hosts/1/alias[3] = galia
93
94 # We can get nodes counting from the right with 'last()-N'
95 test last-minus-one /files/etc/hosts/*[ipaddr = "127.0.0.1"]/alias[ last() - 1 ]
96      /files/etc/hosts/1/alias[2] = galia.watzmann.net
97
98 # Make sure we look at all nodes with a given label (ticket #23)
99 test transparent-multi-node /files/etc/ssh/sshd_config/AcceptEnv/10
100      /files/etc/ssh/sshd_config/AcceptEnv[2]/10 = LC_ADDRESS
101
102 test abbrev-descendants /files/etc/pam.d//1
103      /files/etc/pam.d/login/1
104      /files/etc/pam.d/postgresql/1
105      /files/etc/pam.d/newrole/1
106
107 test descendant-or-self /files/descendant-or-self :: 4
108      /files/etc/ssh/sshd_config/AcceptEnv[1]/4 = LC_TIME
109      /files/etc/ssh/ssh_config/Host/SendEnv[1]/4 = LC_TIME
110      /files/etc/ssh/ssh_config/Host/SendEnv[2]/4 = LC_TELEPHONE
111      /files/etc/aliases/4
112      /files/etc/selinux/semanage.conf/ignoredirs/4 = /dev
113      /files/etc/fstab/4
114      /files/etc/pam.d/login/4
115      /files/etc/pam.d/newrole/4
116      /files/etc/inittab/4
117
118 test descendant /files/etc/aliases/4/descendant::4
119
120 test descendant-or-self-2 /files/etc/aliases/4/descendant-or-self::4
121      /files/etc/aliases/4
122
123 # No matches because the predicate asks if there is a toplevel node
124 # 'ipaddr' with the given value
125 test abs-locpath /files/etc/hosts/*[/ipaddr = '127.0.0.1']/canonical
126
127 test rel-pred /files/etc/hosts/*/canonical[../ipaddr = '127.0.0.1']
128      /files/etc/hosts/1/canonical = localhost.localdomain
129
130 # Not the best way to write this, but entirely acceptable
131 test path-with-parent /files/etc/hosts/*/canonical[../ipaddr = '127.0.0.1']/../alias
132      /files/etc/hosts/1/alias[1] = localhost
133      /files/etc/hosts/1/alias[2] = galia.watzmann.net
134      /files/etc/hosts/1/alias[3] = galia
135
136 test node-exists-pred /files/etc/hosts/*/canonical[../alias]
137      /files/etc/hosts/1/canonical = localhost.localdomain
138      /files/etc/hosts/2/canonical = orange.watzmann.net
139
140 test ipaddr-child //*[ipaddr]
141      /files/etc/hosts/1
142      /files/etc/hosts/2
143
144 test ipaddr-sibling //*[../ipaddr]
145      /files/etc/hosts/1/ipaddr = 127.0.0.1
146      /files/etc/hosts/1/canonical = localhost.localdomain
147      /files/etc/hosts/1/alias[1] = localhost
148      /files/etc/hosts/1/alias[2] = galia.watzmann.net
149      /files/etc/hosts/1/alias[3] = galia
150      /files/etc/hosts/2/ipaddr = 172.31.122.14
151      /files/etc/hosts/2/canonical = orange.watzmann.net
152      /files/etc/hosts/2/alias = orange
153
154 test lircd-ancestor //*[ancestor::kudzu][label() != '#comment']
155      /augeas/files/etc/sysconfig/kudzu/path = /files/etc/sysconfig/kudzu
156      /augeas/files/etc/sysconfig/kudzu/mtime = ...
157      /augeas/files/etc/sysconfig/kudzu/lens = @Shellvars
158      /augeas/files/etc/sysconfig/kudzu/lens/info = ...
159      /files/etc/sysconfig/kudzu/SAFE = no
160
161 test wildcard-last /files/etc/hosts/*[position() = last()]
162      /files/etc/hosts/2
163
164 test wildcard-not-last /files/etc/hosts/*[position() != last()][ipaddr]
165      /files/etc/hosts/1
166
167 test nodeset-nodeset-eq /files/etc/sysconfig/network-scripts/*[BRIDGE = /files/etc/sysconfig/network-scripts/ifcfg-br0/DEVICE]
168      /files/etc/sysconfig/network-scripts/ifcfg-eth0
169
170 test last-ssh-service /files/etc/services/service-name[port = '22'][last()]
171      /files/etc/services/service-name[24] = ssh
172
173 test count-one-alias /files/etc/hosts/*[count(alias) = 1]
174      /files/etc/hosts/2
175
176 test number-gt /files/etc/hosts/*[count(alias) > 1]
177      /files/etc/hosts/1
178
179 test pred-or /files/etc/hosts/*[canonical = 'localhost' or alias = 'localhost']
180      /files/etc/hosts/1
181
182 test pred-and-or /files/etc/hosts/*[(canonical = 'localhost' or alias = 'localhost') and ipaddr = '127.0.0.1']
183      /files/etc/hosts/1
184
185 # We used to parse this as '/files/etc/.' followed by garbage, that
186 # was silently ignored. This path must not match anything, instead of
187 # every child of /files/etc
188 test path-with-dot /files/etc/.notthere
189
190 test str-neq /files/etc/*['foo' != 'foo']
191
192 # label() returns the label of the context node as a string
193 test label-neq /files/etc/hosts/*[label() != '#comment']
194      /files/etc/hosts/1
195      /files/etc/hosts/2
196
197 # 'and' and 'or' need to coerce types to boolean
198 test coerce-or /files[/files/etc/hosts/*[ipaddr = '127.0.0.1'] or /files/etc/aliases/*[name = 'root'] ]
199      /files
200
201 test coerce-and-true /files['foo' and count(/files/etc/hosts/*) ]
202      /files
203
204 test coerce-and-false /files['' and count(/none) and /none]
205
206 test preceding-sibling /files/etc/hosts/*/preceding-sibling::*[alias = 'localhost']
207      /files/etc/hosts/1
208
209 test preceding-sibling-pred /files/etc/grub.conf/*[preceding-sibling::*[1] = ../default]
210      /files/etc/grub.conf/timeout = 5
211
212 test preceding-sibling-pred2 /files/etc/grub.conf/*[preceding-sibling::*[1][self::default]]
213      /files/etc/grub.conf/timeout = 5
214
215 test following-sibling /files/etc/hosts/1/*/following-sibling::alias
216      /files/etc/hosts/1/alias[1] = localhost
217      /files/etc/hosts/1/alias[2] = galia.watzmann.net
218      /files/etc/hosts/1/alias[3] = galia
219
220 test following-sibling-pred /files/etc/hosts/1/*[following-sibling::alias]
221      /files/etc/hosts/1/ipaddr = 127.0.0.1
222      /files/etc/hosts/1/canonical = localhost.localdomain
223      /files/etc/hosts/1/alias[1] = localhost
224      /files/etc/hosts/1/alias[2] = galia.watzmann.net
225
226 test regexp1 /files/etc/sysconfig/network-scripts/*[label() =~ regexp('.*-eth0')]
227      /files/etc/sysconfig/network-scripts/ifcfg-eth0
228
229 test regexp2 /files/etc/hosts/*[* =~ regexp('127\..*')]
230      /files/etc/hosts/1
231
232 test regexp3 /files/etc/hosts/*[ipaddr =~ regexp(/files/etc/hosts/*/ipaddr)]
233      /files/etc/hosts/1
234      /files/etc/hosts/2
235
236 # Check that we don't crash when the nodeset contains all NULL's
237 test regexp4 /files/etc/hosts/*[ipaddr =~ regexp(/files/etc/hosts/*[ipaddr])]
238
239 # Check case-insensitive matches
240 test regexp5 /files/etc/sysconfig/network-scripts/*[label() =~ regexp('.*-ETH0', 'i')]
241      /files/etc/sysconfig/network-scripts/ifcfg-eth0
242
243 test regexp6 /files/etc/hosts/*[ipaddr =~ regexp(/files/etc/hosts/*/ipaddr, 'i')]
244      /files/etc/hosts/1
245      /files/etc/hosts/2
246
247 test glob1 /files[ 'axxa' =~ glob('a*a') ]
248      /files
249
250 test glob2 /files[ 'axxa' =~ glob('a?[a-z]a') ]
251      /files
252
253 test glob3 /files[ '^a' =~ glob('^a') ]
254      /files
255
256 test glob4 /augeas/load/*[ '/etc/hosts' =~ glob(incl) ]
257      /augeas/load/Hosts
258
259 test glob5 /files[ '/files/etc/hosts/1' =~ glob('/files/*/1') ]
260
261 test glob6 /files[ '/files/etc/hosts/1' =~ glob('/files/*/*/1') ]
262      /files
263
264 test glob_nomatch /files/etc/hosts/*[ipaddr][ ipaddr !~ glob(/files/etc/hosts/*/ipaddr[1]) ]
265     /files/etc/hosts/2
266
267 test glob_for_lens /augeas/load/*[ '/etc/hosts/1/ipaddr' =~ glob(incl) + regexp('/.*') ]/lens
268      /augeas/load/Hosts/lens = @Hosts
269
270 # Union of nodesets
271 test union (/files/etc/yum.conf | /files/etc/yum.repos.d/*)/*/gpgcheck
272      /files/etc/yum.conf/main/gpgcheck = 1
273      /files/etc/yum.repos.d/fedora-updates.repo/updates/gpgcheck = 1
274      /files/etc/yum.repos.d/fedora-updates.repo/updates-debuginfo/gpgcheck = 1
275      /files/etc/yum.repos.d/fedora-updates.repo/updates-source/gpgcheck = 1
276      /files/etc/yum.repos.d/fedora.repo/fedora/gpgcheck = 1
277      /files/etc/yum.repos.d/fedora.repo/fedora-debuginfo/gpgcheck = 1
278      /files/etc/yum.repos.d/fedora.repo/fedora-source/gpgcheck = 1
279      /files/etc/yum.repos.d/remi.repo/remi/gpgcheck = 1
280      /files/etc/yum.repos.d/remi.repo/remi-test/gpgcheck = 1
281
282 test else_nodeset_lhs (/files/etc/yum.conf else /files/etc/yum.repos.d/*)/*/gpgcheck
283      /files/etc/yum.conf/main/gpgcheck = 1
284
285 test else_nodeset_rhs (/files/etc/yum.conf.missing else /files/etc/yum.repos.d/fedora.repo)/*/gpgcheck
286      /files/etc/yum.repos.d/fedora.repo/fedora/gpgcheck = 1
287      /files/etc/yum.repos.d/fedora.repo/fedora-debuginfo/gpgcheck = 1
288      /files/etc/yum.repos.d/fedora.repo/fedora-source/gpgcheck = 1
289
290 test else_nodeset_nomatch (/files/left else /files/right)
291
292 # Paths with whitespace in them
293 test php1 $php/mail function
294      /files/etc/php.ini/mail\ function
295
296 test php2 $php[mail function]
297      /files/etc/php.ini
298
299 test php3 $php[count(mail function) = 1]
300      /files/etc/php.ini
301
302 test php4 $php/mail function/SMTP
303      /files/etc/php.ini/mail\ function/SMTP = localhost
304
305 test php5 $php/mail\ function
306      /files/etc/php.ini/mail\ function
307
308 test expr-or /files/etc/group/root/*[self::gid or self::user]
309      /files/etc/group/root/gid = 0
310      /files/etc/group/root/user = root
311
312 test int-ns-eq /files/etc/group/*[int(gid) = 30]
313      /files/etc/group/gopher
314
315 test int-ns-lt /files/etc/group/*[int(gid) < 3]
316     /files/etc/group/root
317     /files/etc/group/bin
318     /files/etc/group/daemon
319
320 test int-bool-f /files[int(1 = 0) > 0]
321
322 test int-bool-t /files[int(1 = 1) > 0]
323      /files
324
325 # Relative paths, relying on default /files context
326 test ctx_file etc/network/interfaces
327      /files/etc/network/interfaces
328
329 test ctx_file_pred etc/network/interfaces/iface[. = "lo"]
330      /files/etc/network/interfaces/iface[1] = lo
331
332 # Test matching with characters that need escaping in the filename
333 test escape1 /files/etc/sysconfig/network-scripts/*
334     /files/etc/sysconfig/network-scripts/ifcfg-eth0
335     /files/etc/sysconfig/network-scripts/ifcfg-wlan0
336     /files/etc/sysconfig/network-scripts/ifcfg-weird\ \[\!\]\ \(used\ to\ fail\)
337     /files/etc/sysconfig/network-scripts/ifcfg-lo
338     /files/etc/sysconfig/network-scripts/ifcfg-br0
339
340 test escape2 /files/etc/sysconfig/network-scripts/ifcfg-weird\ \[\!\]\ \(used\ to\ fail\)/DEVICE
341      /files/etc/sysconfig/network-scripts/ifcfg-weird\ \[\!\]\ \(used\ to\ fail\)/DEVICE = weird
342
343 test escape3 /files/etc/sysconfig/network-scripts/*[DEVICE = 'weird']
344      /files/etc/sysconfig/network-scripts/ifcfg-weird\ \[\!\]\ \(used\ to\ fail\)
345
346 # Test matching in the presence of hidden nodes
347 test hidden1 /files/etc/security/limits.conf/*[label() != '#comment'][1]
348      /files/etc/security/limits.conf/domain[1] = @jackuser
349
350 test seqaxismatchall /files/etc/hosts/seq::*
351      /files/etc/hosts/1
352      /files/etc/hosts/2
353
354 test seqaxismatchpos /files/etc/hosts/seq::*[2]
355      /files/etc/hosts/2
356
357 test seqaxismatchlabel /files/etc/hosts/seq::2
358      /files/etc/hosts/2
359
360 test seqaxismatchregexp /files/etc/hosts/seq::*[canonical =~ regexp('.*orange.*')]
361      /files/etc/hosts/2
362
363 test else_simple_lhs /files/etc/fstab/*[passno='1' else passno='2']/file
364      /files/etc/fstab/1/file = /
365
366 test else_simple_rhs /files/etc/fstab/*[passno='9' else passno='2']/file
367      /files/etc/fstab/2/file = /boot
368      /files/etc/fstab/5/file = /home
369      /files/etc/fstab/8/file = /local
370      /files/etc/fstab/9/file = /var/lib/xen/images
371
372 test else_haschild_lhs /files/etc/hosts/*[alias else alias='orange']/canonical
373      /files/etc/hosts/1/canonical = localhost.localdomain
374      /files/etc/hosts/2/canonical = orange.watzmann.net
375
376 test else_chain1 /files/etc/fstab/*[passno='9' else passno='1' else passno='2']/file
377      /files/etc/fstab/1/file = /
378
379 test else_chain2 /files/etc/fstab/*[passno='9' else passno='8' else passno='2']/file
380      /files/etc/fstab/2/file = /boot
381      /files/etc/fstab/5/file = /home
382      /files/etc/fstab/8/file = /local
383      /files/etc/fstab/9/file = /var/lib/xen/images
384
385 # Although there are nodes matching passno=2 and nodes matching dump=0
386 # there is no node with both
387 test_and_else_lhs /files/etc/fstab/*[passno='2' and ( dump='0' else dump='1')]/file
388
389 test_and_else_rhs /files/etc/fstab/*[passno='2' and ( dump='nemo' else dump='1')]/file
390      /files/etc/fstab/2/file = /boot
391      /files/etc/fstab/5/file = /home
392      /files/etc/fstab/8/file = /local
393      /files/etc/fstab/9/file = /var/lib/xen/images