|
1 use strict; |
|
2 use warnings; |
|
3 use Data::Dumper; |
|
4 |
|
5 use Test::More; |
|
6 use Test::Cmd; |
|
7 |
|
8 my $test = Test::Cmd->new(prog => "blib/script/checkfs.sylvia", workdir => "", verbose => $ENV{TEST_VERBOSE} > 1); |
|
9 ok($test, "test environment"); |
|
10 |
|
11 # $ENV{HARNESS_ACTIVE} |
|
12 |
|
13 my $rc; |
|
14 |
|
15 $test->run(); |
|
16 $rc = $? >> 8; |
|
17 subtest "run w/o args" => sub { |
|
18 isnt($rc, 0, "exit !0"); |
|
19 like($test->stderr, qr/^Usage:/, "Usage"); |
|
20 }; |
|
21 |
|
22 $test->run(args => "-h"); |
|
23 $rc = $? >> 8; |
|
24 subtest "run w/ -h" => sub { |
|
25 is($rc, 0, "exit 0"); |
|
26 like($test->stdout, qr/^Usage:.*^Options/ms, "Usage and Options"); |
|
27 is($test->stderr, "", "stderr should be empty"); |
|
28 }; |
|
29 |
|
30 |
|
31 $test->run(args => "-m"); |
|
32 $rc = $? >> 8; |
|
33 subtest "run w/ -m" => sub { |
|
34 is($rc, 0, "exit 0"); |
|
35 like($test->stdout, qr/^N.*^S.*^O/msi, "looks like manpage"); |
|
36 is($test->stderr, "", "stderr should be empty"); |
|
37 }; |
|
38 |
|
39 # -------------------------------------------------------- |
|
40 # create a fake df with an input line - filesystem is full |
|
41 # -------------------------------------------------------- |
|
42 $test->run(args => "-i '/dev/mapper/ITADMIN-ITADMIN 103109920 95914716 7195204 98% /ITADMIN' '/dev/mapper/ITADMIN-ITADMIN'"); |
|
43 $rc = $? >> 8; |
|
44 diag($test->stdout); |
|
45 diag($test->stderr); |
|
46 subtest "run w/ -i" => sub { |
|
47 is($rc, 2, "line-test for full filesystem exited with critical value"); |
|
48 }; |
|
49 |
|
50 # -------------------------------------------------------- |
|
51 # create a fake df with an input file - filesystem is fine |
|
52 # -------------------------------------------------------- |
|
53 my $ffile = "t/test_input.sylvia"; |
|
54 my @flines; |
|
55 { our @ARGV = ($ffile); |
|
56 @flines = <>; |
|
57 } |
|
58 $rc = $? >> 8; |
|
59 my $fline= $flines[0]; |
|
60 $test->run(args => "-i '$fline' '/dev/mapper/ITADMIN-ITADMIN'"); |
|
61 $rc = $? >> 8; |
|
62 diag($test->stdout); |
|
63 diag($test->stderr); |
|
64 subtest "run w/ -i" => sub { |
|
65 is($rc, 0, "file-test for fine filesystem exited with ok value"); |
|
66 }; |
|
67 |
|
68 |
|
69 done_testing; |
|
70 |
|
71 |