summaryrefslogtreecommitdiff
path: root/t/02_autovac_freeze.t
blob: 26cfbc08e5d8bd221a6442f39a61db8a1e53b4d0 (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
60
61
62
63
64
65
#!perl

## Test the "autovac_freeze" action

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

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

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

$dbh = $cp->test_database_handle();

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

my $S = q{Action 'autovac_freeze'};
my $label = 'POSTGRES_AUTOVAC_FREEZE';

SKIP:
{
    $ver < 80200 and skip 'Cannot test autovac_freeze on old Postgres versions', 8;

$result = $cp->run(q{-w 0%});

## As this is the first alphabetic test, let's make an emergency bailout if
## the server is not reachable at all!
if ($result =~ /ERROR.+cptesting_socket/s) {
    BAIL_OUT 'Could not connect to the testing database server!';
}

$t = qq{$S self-identifies correctly};
like ($result, qr{^$label}, $t);

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

$t=qq{$S fails when called with an invalid option};
like ($cp->run('foobar=12'), qr{Usage:}, $t);

$t=qq{$S fails when called with an invalid --warning option};
like ($cp->run('--warning=40'), qr{ERROR:.+must be a percentage}, $t);

$t=qq{$S fails when called with an invalid --critical option};
like ($cp->run('--critical=50'), qr{ERROR:.+must be a percentage}, $t);

$t=qq{$S flags when database is over freeze threshold};
like ($cp->run('-w 0%'), qr{$label WARNING:.*ardala=\d+%.*?beedeebeedee=\d+%.*?postgres=\d+%.*?template1=\d+%}, $t);

$t=qq{$S flags when database is under freeze threshold};
like ($cp->run('-w 99%'), qr{$label OK:.*ardala=\d+%.*?beedeebeedee=\d+%.*?postgres=\d+%.*?template1=\d+%}, $t);

$t=qq{$S produces MRTG output};
like ($cp->run('--output=mrtg -w 99%'), qr{0\n\d+\n\nardala \| beedeebeedee}, $t);

}

exit;