Imported Upstream version 1.8.0
[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: short
83 Example with only type and path *)
84   let short = "A+ /tmp/foo\n"
85
86   (* Variable: short_tree
87 Tree for <short> *)
88   let short_tree =
89     {
90         "1"
91         { "type" = "A+" }
92         { "path" = "/tmp/foo" }
93     }
94
95   (* Variable: short_mode
96 Example with only 3 fields *)
97   let short_mode = "c+! /tmp/foo ~0755\n"
98
99   (* Variable: short_mode_tree
100 Tree for <short_mode> *)
101   let short_mode_tree =
102     {
103         "1"
104         { "type" = "c+!" }
105         { "path" = "/tmp/foo" }
106         { "mode" = "~0755" }
107     }
108
109   (* Variable: short_uid
110 Example with only 4 fields *)
111   let short_uid = "A+ /tmp/foo   -   0\n"
112
113   (* Variable: short_uid_tree
114 Tree for <short_uid> *)
115   let short_uid_tree =
116     {
117         "1"
118         { "type" = "A+" }
119         { "path" = "/tmp/foo" }
120         { "mode" = "-" }
121         { "uid" = "0" }
122     }
123
124   (* Variable: short_gid
125 Example with only 5 fields *)
126   let short_gid = "z /tmp/bar/foo -\t- augd\n"
127
128   (* Variable: short_gid_tree
129 Tree for <short_gid> *)
130   let short_gid_tree =
131     {
132         "1"
133         { "type" = "z" }
134         { "path" = "/tmp/bar/foo" }
135         { "mode" = "-" }
136         { "uid" = "-" }
137         { "gid" = "augd" }
138     }
139
140   (* Variable: short_age
141 Example with only 6 fields *)
142   let short_age = "H /var/tmp/fooBarFOO - jj jj ~10d\n"
143
144   (* Variable: short_age_tree
145 Tree for <short_age> *)
146   let short_age_tree =
147     {
148         "1"
149         { "type" = "H" }
150         { "path" = "/var/tmp/fooBarFOO" }
151         { "mode" = "-" }
152         { "uid" = "jj" }
153         { "gid" = "jj" }
154         { "age" = "~10d" }
155     }
156
157   (* Variable: complex_arg
158 Complex argument example. That one comes from the manual *)
159   let complex_arg = "t /run/screen - - - - user.name=\"John Smith\" security.SMACK64=screen\n"
160
161   (* Variable: complex_arg_tree
162 Tree for <complex_arg> *)
163   let complex_arg_tree =
164     {
165         "1"
166         { "type" = "t" }
167         { "path" = "/run/screen" }
168         { "mode" = "-" }
169         { "uid" = "-" }
170         { "gid" = "-" }
171         { "age" = "-" }
172         { "argument" = "user.name=\"John Smith\" security.SMACK64=screen" }
173     }
174
175   (* Variable: valid_short_args
176 A short argument value example. *)
177   let valid_short_args = "h /var/log/journal - - - - C\nh /var/log/journal - - - - +C\n"
178
179   (* Variable: valid_short_args_tree
180 Tree for <valid_short_args> *)
181   let valid_short_args_tree =
182     {
183         "1"
184         { "type" = "h" }
185         { "path" = "/var/log/journal" }
186         { "mode" = "-" }
187         { "uid" = "-" }
188         { "gid" = "-" }
189         { "age" = "-" }
190         { "argument" = "C" }
191     }
192     {
193         "2"
194         { "type" = "h" }
195         { "path" = "/var/log/journal" }
196         { "mode" = "-" }
197         { "uid" = "-" }
198         { "gid" = "-" }
199         { "age" = "-" }
200         { "argument" = "+C" }
201     }
202
203   (* Variable: valid_age
204 Example with a complex age. *)
205   let valid_age = "v /var/tmp/js 4221 johnsmith - ~10d12h\n"
206
207   (* Variable: valid_age_tree
208 Tree for <valid_age> *)
209   let valid_age_tree =
210     {
211         "1"
212         { "type" = "v" }
213         { "path" = "/var/tmp/js" }
214         { "mode" = "4221" }
215         { "uid" = "johnsmith" }
216         { "gid" = "-" }
217         { "age" = "~10d12h" }
218     }
219
220   (* Variable: valid_second
221 Example with full age unit *)
222   let valid_second = "p+ /var/tmp - jsmith - 0second\n"
223
224   (* Variable: valid_second_tree
225 Tree for <valid_second> *)
226   let valid_second_tree =
227     {
228         "1"
229         { "type" = "p+" }
230         { "path" = "/var/tmp" }
231         { "mode" = "-" }
232         { "uid" = "jsmith" }
233         { "gid" = "-" }
234         { "age" = "0second" }
235     }
236
237   (* Variable: valid_days
238 Example with full age unit (plural) *)
239   let valid_days = "x /var/tmp/manu - jonhsmith - 9days\n"
240
241   (* Variable: valid_days_tree
242 Tree for <valid_days> *)
243   let valid_days_tree =
244     {
245         "1"
246         { "type" = "x" }
247         { "path" = "/var/tmp/manu" }
248         { "mode" = "-" }
249         { "uid" = "jonhsmith" }
250         { "gid" = "-" }
251         { "age" = "9days" }
252     }
253
254   (* Variable: percent
255 Test with a percent sign *)
256   let percent = "m /var/log/%m 2755 root systemdjournal - -\n"
257
258   (* Variable: percent_tree
259 Tree for <percent> *)
260   let percent_tree =
261     {
262         "1"
263         { "type" = "m" }
264         { "path" = "/var/log/%m" }
265         { "mode" = "2755" }
266         { "uid" = "root" }
267         { "gid" = "systemdjournal" }
268         { "age" = "-" }
269         { "argument" = "-" }
270     }
271
272   (* Variable: hyphen
273 Test with a hyphen in gid *)
274   let hyphen = "L /var/log/journal 2755 root systemd-journal - -\n"
275
276   (* Variable: hyphen_tree
277 Tree for <hyphen> *)
278   let hyphen_tree =
279     {
280         "1"
281         { "type" = "L" }
282         { "path" = "/var/log/journal" }
283         { "mode" = "2755" }
284         { "uid" = "root" }
285         { "gid" = "systemd-journal" }
286         { "age" = "-" }
287         { "argument" = "-" }
288     }
289
290   (* Variable: valid_base
291 A valid test to be re-used by the failure cases *)
292   let valid_base = "H /var/tmp/js 0000 jonhsmith 60 1s foo\n"
293
294   (* Variable: valid_base_tree
295 Tree for <valid_base> *)
296   let valid_base_tree =
297     {
298         "1"
299         { "type" = "H" }
300         { "path" = "/var/tmp/js" }
301         { "mode" = "0000" }
302         { "uid" = "jonhsmith" }
303         { "gid" = "60" }
304         { "age" = "1s" }
305         { "argument" = "foo" }
306     }
307
308   (* Variable: mode3
309 Mode field example with only three digits *)
310   let mode3 = "c+! /tmp/foo 755\n"
311
312   (* Variable: mode3_tree
313 Tree for <mode3> *)
314   let mode3_tree =
315     {
316         "1"
317         { "type" = "c+!" }
318         { "path" = "/tmp/foo" }
319         { "mode" = "755" }
320     }
321
322 (************************************************************************
323  * Group:                 INVALID EXAMPLES
324  *************************************************************************)
325
326   (* Variable: invalid_too_short
327 Invalid example that do not contain path *)
328   let invalid_too_short = "H\n"
329
330   (* Variable: invalid_age
331 Invalid example that contain invalid age  *)
332   let invalid_age = "H /var/tmp/js 0000 jonhsmith 60 1sss foo\n"
333
334   (* Variable: invalid_type
335 Invalid example that contain invalid type (bad letter) *)
336   let invalid_type = "e /var/tmp/js 0000 jonhsmith 60 1s foo\n"
337
338   (* Variable: invalid_type_num
339  Invalid example that contain invalid type (numeric) *)
340   let invalid_type_num = "1 /var/tmp/js 0000 jonhsmith 60 1s foo\n"
341
342   (* Variable: invalid_mode
343 Invalid example that contain invalid mode (bad int) *)
344   let invalid_mode = "H /var/tmp/js 8000 jonhsmith 60 1s foo\n"
345
346   (* Variable: invalid_mode_alpha
347 Invalid example that contain invalid mode (letter) *)
348   let invalid_mode_alpha = "H /var/tmp/js a000 jonhsmith 60 1s foo\n"
349
350   test Tmpfiles.lns get simple = simple_tree
351
352   test Tmpfiles.lns get complex = complex_tree
353
354   test Tmpfiles.lns get trailing_ws = complex_tree
355
356   test Tmpfiles.lns get empty = {}{}{}
357
358   test Tmpfiles.lns get exclamation_mark = exclamation_mark_tree
359
360   test Tmpfiles.lns get short = short_tree
361
362   test Tmpfiles.lns get short_mode = short_mode_tree
363
364   test Tmpfiles.lns get short_uid = short_uid_tree
365
366   test Tmpfiles.lns get short_gid = short_gid_tree
367
368   test Tmpfiles.lns get short_age = short_age_tree
369
370   test Tmpfiles.lns get complex_arg = complex_arg_tree
371
372   test Tmpfiles.lns get valid_short_args = valid_short_args_tree
373
374   test Tmpfiles.lns get valid_second = valid_second_tree
375
376   test Tmpfiles.lns get valid_days = valid_days_tree
377
378   test Tmpfiles.lns get valid_age = valid_age_tree
379
380   test Tmpfiles.lns get percent = percent_tree
381
382   test Tmpfiles.lns get hyphen = hyphen_tree
383
384   test Tmpfiles.lns get valid_base = valid_base_tree
385
386   test Tmpfiles.lns get mode3 = mode3_tree
387
388
389 (* failure cases *)
390
391   test Tmpfiles.lns get invalid_too_short = *
392
393   test Tmpfiles.lns get invalid_age = *
394
395   test Tmpfiles.lns get invalid_type = *
396
397   test Tmpfiles.lns get invalid_type_num = *
398
399   test Tmpfiles.lns get invalid_mode = *
400
401   test Tmpfiles.lns get invalid_mode_alpha = *
402
403 (* Local Variables: *)
404 (* mode: caml       *)
405 (* End:             *)