t/00-basic.t
changeset 21 2247be0e2a13
child 40 d0410b54a231
equal deleted inserted replaced
20:92818898bb2c 21:2247be0e2a13
       
     1 
       
     2 use 5.014;
       
     3 no strict 'subs';
       
     4 use Test::More;
       
     5 use Test::Exception;
       
     6 use English qw(-no_match_vars);
       
     7 
       
     8 package FOO;
       
     9 ::require_ok 'blib/nagios/plugins/ius/check_amanda-client';
       
    10 
       
    11 package main;
       
    12 
       
    13 subtest 'find_tool' => sub {
       
    14     is FOO::find_tool('sh'), '/bin/sh' => 'found /bin/sh';
       
    15     dies_ok { FOO: find_tool('abc123xyz-unknown-tool') }
       
    16     'dies for unknown tool';
       
    17 };
       
    18 
       
    19 subtest 'check_perms' => sub {
       
    20     my ($mode, $owner, $group) = (stat $EXECUTABLE_NAME)[2, 4, 5];
       
    21     $mode &= 07777;
       
    22 
       
    23     ok FOO::check_perms($EXECUTABLE_NAME, $mode, $owner, $group),
       
    24       "perms of $EXECUTABLE_NAME 1";
       
    25     ok FOO::check_perms(
       
    26         $EXECUTABLE_NAME, $mode,
       
    27         scalar(getpwuid $owner),
       
    28         scalar(getgrgid $group)
       
    29       ),
       
    30       "perms of $EXECUTABLE_NAME 2";
       
    31     dies_ok { FOO::check_perms($EXECUTABLE_NAME, $mode, $owner + 1, $group) }
       
    32     'dies on wrong perms';
       
    33 };
       
    34 
       
    35 subtest 'config_names' => sub {
       
    36     is_deeply [sort +FOO::config_names('t/etc/amanda')],
       
    37       [sort qw(foobar DailySet1 WeeklySet1)] => 'got configs';
       
    38     dies_ok { FOO::config_names('t/etc/no-amanda') } 'dies on missing configs';
       
    39 };
       
    40 
       
    41 subtest 'file systems' => sub {
       
    42     my @fs = do {
       
    43 	local @ARGV = ('/proc/filesystems');
       
    44 	map { /(\S+)/ } grep { not /^nodev/ } <>;
       
    45     };
       
    46     my @devs =
       
    47       sort { $a->[0] cmp $b->[0] }
       
    48       map { [$_->[0], (stat $_->[0])[0]] }
       
    49       grep { $_->[1] ~~ @fs }
       
    50       map { [(split)[6, 1]] } `df -PT`;
       
    51     ok scalar @fs => 'have file systems for testing';
       
    52     ok scalar @devs => 'have devices for testing';
       
    53     is_deeply [sort { $a->[0] cmp $b->[0] } FOO::get_devices()],
       
    54       \@devs => 'got the proper devices';
       
    55 
       
    56 };
       
    57 
       
    58 done_testing;