summaryrefslogtreecommitdiff
path: root/t/02_disk_space.t
blob: 1b58ccdc86b146ec55871e948212c944d8f6561e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!perl

## Test the "disk_space" action

use 5.006;
use strict;
use warnings;
use Data::Dumper;
use Test::More;
use lib 't','.';
use CP_Testing;

# df might fail in chroot environments, e.g. on build daemons where
# check-postgres packages are built
system q{df > /dev/null 2>&1};
if ($?) {
    plan skip_all => 'Skipping disk_space tests because df does not work';
} else {
    plan tests => 8;
}

use vars qw/$dbh $result $t $host $dbname/;

my $cp = CP_Testing->new( {default_action => 'disk_space'} );

$dbh = $cp->test_database_handle();
$dbh->{AutoCommit} = 1;
$dbname = $cp->get_dbname;
$host = $cp->get_host();

my $S = q{Action 'disk_space'};
my $label = q{POSTGRES_DISK_SPACE};

$t = qq{$S identifies self};
$result = $cp->run('-w 999z');
like($result, qr{$label}, $t);

$t = qq{$S identifies host};
like ($result, qr{host:$host}, $t);

$t = qq{$S reports file system};
like ($result, qr{FS .* mounted on /.*? is using }, $t); # in some build environments, the filesystem is reported as "-"

$t = qq{$S reports usage};
like ($result, qr{ is using \d*\.\d+ [A-Z]B of \d*\.\d+ [A-Z]B}, $t);

$t = qq{$S notes plenty of available space};
like ($result, qr{$label OK}, $t);

$t = qq{$S flags insufficient space};
like ($cp->run('-w 1b'), qr{$label WARNING:}, $t);

$t = qq{$S flags insufficient space};
like ($cp->run('-w "999z or 1%"'), qr{$label WARNING:}, $t);

$t = qq{$S reports MRTG output};
like ($cp->run('--output=mrtg'), qr{\A\d+\n0\n\n.*\n}, $t);

exit;