1#######################################################
2#
3# Test filestat()
4#
5#######################################################
6
7body common control
8{
9      inputs => { "../../default.cf.sub" };
10      bundlesequence  => { default("$(this.promise_filename)") };
11      version => "1.0";
12}
13
14#######################################################
15
16bundle agent init
17{
18  files:
19      "$(G.testfile)"
20      create => "true",
21      perms => init_m(600),
22      edit_defaults => init_empty,
23      edit_line => init_fill_in;
24
25  reports:
26    DEBUG::
27      "Created $(G.testfile)";
28}
29
30body edit_defaults init_empty
31{
32      empty_file_before_editing => "true";
33      edit_backup => "false";
34}
35
36body perms init_m(mode)
37{
38      mode   => "$(mode)";
39}
40
41bundle edit_line init_fill_in
42{
43  insert_lines:
44      "012345789";
45      "112345789";
46      "212345789";
47      "312345789";
48      "4";
49}
50
51body delete init_delete
52{
53      dirlinks => "delete";
54      rmdirs   => "true";
55}
56
57
58#######################################################
59
60bundle agent test
61{
62  vars:
63      "fields" slist => splitstring("size,gid,uid,ino,nlink,ctime,atime,mtime,mode,modeoct,permstr,permoct,type,devno,dev_minor,dev_major,basename,dirname,linktarget,linktarget_shallow", ",", 999);
64
65      "stat[$(fields)]" string => filestat($(G.testfile), $(fields));
66}
67
68
69#######################################################
70
71bundle agent check
72{
73  vars:
74      "expected[type]" string => "regular file";
75      "expected[nlink]" string => "1";
76      "expected[dirname]" string => dirname($(G.testfile));
77      "expected[basename]" string => lastnode($(G.testfile), escape("$(const.dirsep)"));
78      "expected[linktarget]" string => $(G.testfile);
79      "expected[linktarget_shallow]" string => $(G.testfile);
80
81    windows::
82      "expected[size]" string => "47";
83      "expected[mode]" string => "33206"; # 100666
84      "expected[permoct]" string => "666";
85      "expected[modeoct]" string => "100666";
86      "expected[permstr]" string => "-rw-rw-rw-";
87    !windows::
88      "expected[size]" string => "42";
89      "expected[mode]" string => "33152"; # 100600
90      "expected[permoct]" string => "600";
91      "expected[modeoct]" string => "100600";
92      "expected[permstr]" string => "-rw-------";
93
94    any::
95      "expects" slist => getindices("expected");
96
97      "fields" slist => getindices("test.stat");
98
99      "joint_condition" string => join(".", "expects");
100  classes:
101      "$(expects)" expression => strcmp("$(test.stat[$(expects)])", "$(expected[$(expects)])");
102      "ok" expression => "$(joint_condition)";
103
104  reports:
105    DEBUG::
106      "got $(G.testfile) field $(fields)=$(test.stat[$(fields)])";
107
108      "got $(G.testfile) field $(expects)=$(test.stat[$(expects)]) matches expected"
109      if => "$(expects)";
110
111      "got $(G.testfile) field $(expects)=$(test.stat[$(expects)]) did NOT match expected $(expected[$(expects)])"
112      if => "!$(expects)";
113
114    ok::
115      "$(this.promise_filename) Pass";
116    !ok::
117      "$(this.promise_filename) FAIL";
118}
119