Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / tests / test_tmpfiles.aug
1 (*
2 Module: Test_Tmpfiles
3   Provides unit tests and examples for the <Tmpfiles> lens.
4 *)
5
6 module Test_Tmpfiles =
7
8 (************************************************************************
9  * Group:                 VALID EXAMPLES
10  *************************************************************************)
11   (* Variable: simple
12 One line, simple example *)
13   let simple = "d /run/user 0755 root mysql 10d -\n"
14
15   (* Variable: simple_tree
16 Tree for <simple> *)
17   let simple_tree =
18     {
19         "1"
20         { "type" = "d" }
21         { "path" = "/run/user" }
22         { "mode" = "0755" }
23         { "uid" = "root" }
24         { "gid" = "mysql" }
25         { "age" = "10d" }
26         { "argument" = "-" }
27     }
28
29   (* Variable: complex
30 A more complex example, comes from the manual *)
31   let complex = "#Type Path        Mode UID  GID  Age Argument\nd    /run/user   0755 root root 10d -\nL    /tmp/foobar -    -    -    -   /dev/null\n"
32
33   (* Variable: complex_tree
34 Tree for <complex> and <trailing_ws> *)
35   let complex_tree =
36       { "#comment" = "Type Path        Mode UID  GID  Age Argument" }
37       { "1"
38         { "type" = "d" }
39         { "path" = "/run/user" }
40         { "mode" = "0755" }
41         { "uid" = "root" }
42         { "gid" = "root" }
43         { "age" = "10d" }
44         { "argument" = "-" }
45       }
46       { "2"
47         { "type" = "L" }
48         { "path" = "/tmp/foobar" }
49         { "mode" = "-" }
50         { "uid" = "-" }
51         { "gid" = "-" }
52         { "age" = "-" }
53         { "argument" = "/dev/null" }
54       }
55
56   (* Variable: trailing_ws
57 The complex example with extra spaces *)
58   let trailing_ws = "  #Type Path        Mode UID  GID  Age Argument  \n    d    /run/user   0755 root root 10d -   \t\n    L    /tmp/foobar -    -    -    -   /dev/null\t\n"
59
60   (* Variable: empty
61 Empty example *)
62   let empty = "\n\n\n"
63
64   (* Variable: exclamation_mark
65 Example with an exclamation mark in the type *)
66   let exclamation_mark = "D! /tmp/foo - - - - -\n"
67
68   (* Variable: exclamation_mark_tree
69 Tree for <exclamation_mark> *)
70   let exclamation_mark_tree =
71     {
72         "1"
73         { "type" = "D!" }
74         { "path" = "/tmp/foo" }
75         { "mode" = "-" }
76         { "uid" = "-" }
77         { "gid" = "-" }
78         { "age" = "-" }
79         { "argument" = "-" }
80     }
81
82   (* Variable: minus
83 Example with an minus mark in the type *)
84   let minus = "D- /tmp/foo - - - - -\n"
85
86   (* Variable: minus_tree
87 Tree for <minus_tree> *)
88   let minus_tree =
89     {
90         "1"
91         { "type" = "D-" }
92         { "path" = "/tmp/foo" }
93         { "mode" = "-" }
94         { "uid" = "-" }
95         { "gid" = "-" }
96         { "age" = "-" }
97         { "argument" = "-" }
98     }
99
100   (* Variable: equal
101 Example with an equal sign in the type *)
102   let equal = "d= /tmp/foo 0755 root root - -\n"
103
104   (* Variable: equal_tree
105 Tree for <equal> *)
106   let equal_tree =
107     {
108         "1"
109         { "type" = "d=" }
110         { "path" = "/tmp/foo" }
111         { "mode" = "0755" }
112         { "uid" = "root" }
113         { "gid" = "root" }
114         { "age" = "-" }
115         { "argument" = "-" }
116     }
117
118   (* Variable: tilde
119 Example with a tilde character in the type *)
120   let tilde = "w~ /tmp/foo 0755 root root - dGVzdAo=\n"
121
122   (* Variable: tilde_tree
123 Tree for <tilde> *)
124   let tilde_tree =
125     {
126         "1"
127         { "type" = "w~" }
128         { "path" = "/tmp/foo" }
129         { "mode" = "0755" }
130         { "uid" = "root" }
131         { "gid" = "root" }
132         { "age" = "-" }
133         { "argument" = "dGVzdAo=" }
134     }
135
136   (* Variable: caret
137 Example with a caret in the type *)
138   let caret = "f^ /etc/motd.d/50-provision.conf - - - - login.motd\n"
139
140   (* Variable: caret_tree
141 Tree for <caret> *)
142   let caret_tree =
143     {
144         "1"
145         { "type" = "f^" }
146         { "path" = "/etc/motd.d/50-provision.conf" }
147         { "mode" = "-" }
148         { "uid" = "-" }
149         { "gid" = "-" }
150         { "age" = "-" }
151         { "argument" = "login.motd" }
152     }
153
154   (* Variable: short
155 Example with only type and path *)
156   let short = "A+ /tmp/foo\n"
157
158   (* Variable: short_tree
159 Tree for <short> *)
160   let short_tree =
161     {
162         "1"
163         { "type" = "A+" }
164         { "path" = "/tmp/foo" }
165     }
166
167   (* Variable: short_mode
168 Example with only 3 fields *)
169   let short_mode = "c+! /tmp/foo ~0755\n"
170
171   (* Variable: short_mode_tree
172 Tree for <short_mode> *)
173   let short_mode_tree =
174     {
175         "1"
176         { "type" = "c+!" }
177         { "path" = "/tmp/foo" }
178         { "mode" = "~0755" }
179     }
180
181   (* Variable: short_uid
182 Example with only 4 fields *)
183   let short_uid = "A+ /tmp/foo   -   0\n"
184
185   (* Variable: short_uid_tree
186 Tree for <short_uid> *)
187   let short_uid_tree =
188     {
189         "1"
190         { "type" = "A+" }
191         { "path" = "/tmp/foo" }
192         { "mode" = "-" }
193         { "uid" = "0" }
194     }
195
196   (* Variable: short_gid
197 Example with only 5 fields *)
198   let short_gid = "z /tmp/bar/foo -\t- augd\n"
199
200   (* Variable: short_gid_tree
201 Tree for <short_gid> *)
202   let short_gid_tree =
203     {
204         "1"
205         { "type" = "z" }
206         { "path" = "/tmp/bar/foo" }
207         { "mode" = "-" }
208         { "uid" = "-" }
209         { "gid" = "augd" }
210     }
211
212   (* Variable: short_age
213 Example with only 6 fields *)
214   let short_age = "H /var/tmp/fooBarFOO - jj jj ~10d\n"
215
216   (* Variable: short_age_tree
217 Tree for <short_age> *)
218   let short_age_tree =
219     {
220         "1"
221         { "type" = "H" }
222         { "path" = "/var/tmp/fooBarFOO" }
223         { "mode" = "-" }
224         { "uid" = "jj" }
225         { "gid" = "jj" }
226         { "age" = "~10d" }
227     }
228
229   (* Variable: complex_arg
230 Complex argument example. That one comes from the manual *)
231   let complex_arg = "t /run/screen - - - - user.name=\"John Smith\" security.SMACK64=screen\n"
232
233   (* Variable: complex_arg_tree
234 Tree for <complex_arg> *)
235   let complex_arg_tree =
236     {
237         "1"
238         { "type" = "t" }
239         { "path" = "/run/screen" }
240         { "mode" = "-" }
241         { "uid" = "-" }
242         { "gid" = "-" }
243         { "age" = "-" }
244         { "argument" = "user.name=\"John Smith\" security.SMACK64=screen" }
245     }
246
247   (* Variable: valid_short_args
248 A short argument value example. *)
249   let valid_short_args = "h /var/log/journal - - - - C\nh /var/log/journal - - - - +C\n"
250
251   (* Variable: valid_short_args_tree
252 Tree for <valid_short_args> *)
253   let valid_short_args_tree =
254     {
255         "1"
256         { "type" = "h" }
257         { "path" = "/var/log/journal" }
258         { "mode" = "-" }
259         { "uid" = "-" }
260         { "gid" = "-" }
261         { "age" = "-" }
262         { "argument" = "C" }
263     }
264     {
265         "2"
266         { "type" = "h" }
267         { "path" = "/var/log/journal" }
268         { "mode" = "-" }
269         { "uid" = "-" }
270         { "gid" = "-" }
271         { "age" = "-" }
272         { "argument" = "+C" }
273     }
274
275   (* Variable: valid_age
276 Example with a complex age. *)
277   let valid_age = "v /var/tmp/js 4221 johnsmith - ~10d12h\n"
278
279   (* Variable: valid_age_tree
280 Tree for <valid_age> *)
281   let valid_age_tree =
282     {
283         "1"
284         { "type" = "v" }
285         { "path" = "/var/tmp/js" }
286         { "mode" = "4221" }
287         { "uid" = "johnsmith" }
288         { "gid" = "-" }
289         { "age" = "~10d12h" }
290     }
291
292   (* Variable: valid_second
293 Example with full age unit *)
294   let valid_second = "p+ /var/tmp - jsmith - 0second\n"
295
296   (* Variable: valid_second_tree
297 Tree for <valid_second> *)
298   let valid_second_tree =
299     {
300         "1"
301         { "type" = "p+" }
302         { "path" = "/var/tmp" }
303         { "mode" = "-" }
304         { "uid" = "jsmith" }
305         { "gid" = "-" }
306         { "age" = "0second" }
307     }
308
309   (* Variable: valid_days
310 Example with full age unit (plural) *)
311   let valid_days = "x /var/tmp/manu - jonhsmith - 9days\n"
312
313   (* Variable: valid_days_tree
314 Tree for <valid_days> *)
315   let valid_days_tree =
316     {
317         "1"
318         { "type" = "x" }
319         { "path" = "/var/tmp/manu" }
320         { "mode" = "-" }
321         { "uid" = "jonhsmith" }
322         { "gid" = "-" }
323         { "age" = "9days" }
324     }
325
326   (* Variable: percent
327 Test with a percent sign *)
328   let percent = "m /var/log/%m 2755 root systemdjournal - -\n"
329
330   (* Variable: percent_tree
331 Tree for <percent> *)
332   let percent_tree =
333     {
334         "1"
335         { "type" = "m" }
336         { "path" = "/var/log/%m" }
337         { "mode" = "2755" }
338         { "uid" = "root" }
339         { "gid" = "systemdjournal" }
340         { "age" = "-" }
341         { "argument" = "-" }
342     }
343
344   (* Variable: hyphen
345 Test with a hyphen in gid *)
346   let hyphen = "L /var/log/journal 2755 root systemd-journal - -\n"
347
348   (* Variable: hyphen_tree
349 Tree for <hyphen> *)
350   let hyphen_tree =
351     {
352         "1"
353         { "type" = "L" }
354         { "path" = "/var/log/journal" }
355         { "mode" = "2755" }
356         { "uid" = "root" }
357         { "gid" = "systemd-journal" }
358         { "age" = "-" }
359         { "argument" = "-" }
360     }
361
362   (* Variable: valid_base
363 A valid test to be re-used by the failure cases *)
364   let valid_base = "H /var/tmp/js 0000 jonhsmith 60 1s foo\n"
365
366   (* Variable: valid_base_tree
367 Tree for <valid_base> *)
368   let valid_base_tree =
369     {
370         "1"
371         { "type" = "H" }
372         { "path" = "/var/tmp/js" }
373         { "mode" = "0000" }
374         { "uid" = "jonhsmith" }
375         { "gid" = "60" }
376         { "age" = "1s" }
377         { "argument" = "foo" }
378     }
379
380   (* Variable: mode3
381 Mode field example with only three digits *)
382   let mode3 = "c+! /tmp/foo 755\n"
383
384   (* Variable: mode3_tree
385 Tree for <mode3> *)
386   let mode3_tree =
387     {
388         "1"
389         { "type" = "c+!" }
390         { "path" = "/tmp/foo" }
391         { "mode" = "755" }
392     }
393
394   (* Variable: mode_colon
395 Mode field with colon prefix *)
396   let mode_colon = "d- /root :0700 root :root\n"
397
398   (* Variable: mode_colon_tree
399 Tree for <mode_colon> *)
400   let mode_colon_tree =
401     {
402         "1"
403         { "type" = "d-" }
404         { "path" = "/root" }
405         { "mode" = ":0700" }
406         { "uid" = "root" }
407         { "gid" = ":root" }
408     }
409
410 (************************************************************************
411  * Group:                 INVALID EXAMPLES
412  *************************************************************************)
413
414   (* Variable: invalid_too_short
415 Invalid example that do not contain path *)
416   let invalid_too_short = "H\n"
417
418   (* Variable: invalid_age
419 Invalid example that contain invalid age  *)
420   let invalid_age = "H /var/tmp/js 0000 jonhsmith 60 1sss foo\n"
421
422   (* Variable: invalid_type
423 Invalid example that contain invalid type (bad letter) *)
424   let invalid_type = "i /var/tmp/js 0000 jonhsmith 60 1s foo\n"
425
426   (* Variable: invalid_type_num
427  Invalid example that contain invalid type (numeric) *)
428   let invalid_type_num = "1 /var/tmp/js 0000 jonhsmith 60 1s foo\n"
429
430   (* Variable: invalid_mode
431 Invalid example that contain invalid mode (bad int) *)
432   let invalid_mode = "H /var/tmp/js 8000 jonhsmith 60 1s foo\n"
433
434   (* Variable: invalid_mode_alpha
435 Invalid example that contain invalid mode (letter) *)
436   let invalid_mode_alpha = "H /var/tmp/js a000 jonhsmith 60 1s foo\n"
437
438   test Tmpfiles.lns get simple = simple_tree
439
440   test Tmpfiles.lns get complex = complex_tree
441
442   test Tmpfiles.lns get trailing_ws = complex_tree
443
444   test Tmpfiles.lns get empty = {}{}{}
445
446   test Tmpfiles.lns get exclamation_mark = exclamation_mark_tree
447
448   test Tmpfiles.lns get minus = minus_tree
449
450   test Tmpfiles.lns get equal = equal_tree
451
452   test Tmpfiles.lns get tilde = tilde_tree
453
454   test Tmpfiles.lns get caret = caret_tree
455
456   test Tmpfiles.lns get short = short_tree
457
458   test Tmpfiles.lns get short_mode = short_mode_tree
459
460   test Tmpfiles.lns get short_uid = short_uid_tree
461
462   test Tmpfiles.lns get short_gid = short_gid_tree
463
464   test Tmpfiles.lns get short_age = short_age_tree
465
466   test Tmpfiles.lns get complex_arg = complex_arg_tree
467
468   test Tmpfiles.lns get valid_short_args = valid_short_args_tree
469
470   test Tmpfiles.lns get valid_second = valid_second_tree
471
472   test Tmpfiles.lns get valid_days = valid_days_tree
473
474   test Tmpfiles.lns get valid_age = valid_age_tree
475
476   test Tmpfiles.lns get percent = percent_tree
477
478   test Tmpfiles.lns get hyphen = hyphen_tree
479
480   test Tmpfiles.lns get valid_base = valid_base_tree
481
482   test Tmpfiles.lns get mode3 = mode3_tree
483
484   test Tmpfiles.lns get mode_colon = mode_colon_tree
485
486
487 (* failure cases *)
488
489   test Tmpfiles.lns get invalid_too_short = *
490
491   test Tmpfiles.lns get invalid_age = *
492
493   test Tmpfiles.lns get invalid_type = *
494
495   test Tmpfiles.lns get invalid_type_num = *
496
497   test Tmpfiles.lns get invalid_mode = *
498
499   test Tmpfiles.lns get invalid_mode_alpha = *
500
501 (* Local Variables: *)
502 (* mode: caml       *)
503 (* End:             *)