summaryrefslogtreecommitdiff
path: root/t/02_logfile.t
blob: 15de979d864751df31b98dccfc84a9d53eecec03 (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
66
67
68
69
#!perl

## Test the "logfile" action
## this does not test $S for syslog or stderr output

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

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

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

$dbh = $cp->test_database_handle();

## Remove any old fake schema
$cp->drop_schema_if_exists();

$host = $cp->get_host();
$dbname = $cp->get_dbname();

my $S = q{Action 'logfile'};
my $label = 'POSTGRES_LOGFILE';

my $logfile = 'test_database_check_postgres/pg.log';

my $cmd = $cp->get_command("--logfile=$logfile");

$result = $cp->run("--logfile=$logfile");

$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 correctly identifies logfile};
like ($result, qr{logs to: $logfile}, $t);

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

$t = qq{$S returned expected text};
like ($result, qr{\bOK\b}, $t);

$t = qq{$S flagged missing logfile param};
like ($cp->run(''), qr{^ERROR:.*redirected.*stderr}, $t);

$t = qq{$S flagged erroneous logfile param};
like ($result = $cp->run("--logfile $logfile" . 'x'), qr{^$label\b}, $t);

$t = qq{$S covers unknown};
like ($result, qr{\bUNKNOWN\b}, $t);

$t = qq{$S covers warning};
like ($cp->run("--warning=1 --logfile $logfile" . 'x'), qr{\bWARNING\b}, $t);

$t = qq{$S returns correct MRTG (OK)};
is ($cp->run("--output=mrtg --warning=1 --logfile $logfile"), qq{1\n0\n\n\n}, $t);

$t = qq{$S returns correct MRTG (fail)};
is ($cp->run("--output=mrtg --warning=1 --logfile $logfile" . 'x'),
    qq{ERROR: logfile ${logfile}x does not exist!\n}, $t);

exit;