root/resources/tests/t/03-filecount.t

Revision 84f1edad405a22f168318effd9be4df3505cc4b0, 2.5 kB (checked in by Mark Harrison <mark@omniti.com>, 4 years ago)

Core::FileCount? module - count matching files

Replaces:

FILECOUNT
LARGEFILES
NEWFILES
OLDFILES

git-svn-id: https://labs.omniti.com/resmon/branches/resmon2@359 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55

  • Property mode set to 100644
Line 
1 use Test::More tests => 13;
2
3 use POSIX qw(strftime);
4
5 use File::Temp;
6
7 use ResmonTest;
8
9 my $dirname = File::Temp::tempdir(CLEANUP => 1);
10
11 my $module;
12 my $results;
13
14 $module = ResmonTest::load_module('Core::FileCount', "$dirname");
15 $results = $module->handler();
16 is_deeply($results, { "count" => [0, "i"] }, "Empty Directory, no filters");
17
18 open(FH, ">$dirname/foo"); close(FH);
19 $results = $module->handler();
20 is_deeply($results, { "count" => [1, "i"] }, "One file, no filters");
21
22 open(FH, ">$dirname/bar"); close(FH);
23 $results = $module->handler();
24 is_deeply($results, { "count" => [2, "i"] }, "Two files, no filters");
25
26 $module = ResmonTest::load_module('Core::FileCount', "$dirname",
27     "filename" => "ba");
28 $results = $module->handler();
29 is_deeply($results, { "count" => [1, "i"] }, "Filename filter: ba (bar)");
30
31 open(FH, ">$dirname/baz"); close(FH);
32 $results = $module->handler();
33 is_deeply($results, { "count" => [2, "i"] }, "Filename filter: ba (bar, baz)");
34
35 my $now = time;
36 my $then = $now - 300;
37 utime $then, $then, "$dirname/baz";
38
39 $module = ResmonTest::load_module('Core::FileCount', "$dirname",
40     "min_modified" => "150");
41 $results = $module->handler();
42 is_deeply($results, { "count" => [1, "i"] }, "min_modified - 1 file");
43
44 utime $then, $then, "$dirname/bar";
45 $results = $module->handler();
46 is_deeply($results, { "count" => [2, "i"] }, "min_modified - 2 files");
47
48 $module = ResmonTest::load_module('Core::FileCount', "$dirname",
49     "max_modified" => "150");
50 $results = $module->handler();
51 is_deeply($results, { "count" => [1, "i"] }, "max_modified - 1 file");
52 utime $now, $now, "$dirname/baz";
53
54 $module = ResmonTest::load_module('Core::FileCount', "$dirname",
55     "min_size" => "1");
56 $results = $module->handler();
57 is_deeply($results, { "count" => [0, "i"] }, "min_size - 0 files");
58
59 open(FH, ">$dirname/foo"); print FH "foobar\n"; close(FH);
60 $results = $module->handler();
61 is_deeply($results, { "count" => [1, "i"] }, "min_size - 1 file");
62
63 $module = ResmonTest::load_module('Core::FileCount', "$dirname",
64     "max_size" => "1");
65 $results = $module->handler();
66 is_deeply($results, { "count" => [2, "i"] }, "max_size - 2 files");
67
68 $module = ResmonTest::load_module('Core::FileCount', "$dirname",
69     "permissions" => "06[04][04]");
70 $results = $module->handler();
71 is_deeply($results, { "count" => [3, "i"] }, "permissions - 3 files");
72
73 chmod 0666, "$dirname/foo";
74 $results = $module->handler();
75 is_deeply($results, { "count" => [2, "i"] }, "permissions - 2 files");
76
77 # Unable to test uid/gid without root access
Note: See TracBrowser for help on using the browser.