summaryrefslogtreecommitdiff
path: root/t/02_version.t
blob: 77703ac95b8d027677faab9e894335d9c7ea31b2 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!perl

## Test the "version" action

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

use vars qw/$dbh $SQL $t/;

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

$dbh = $cp->test_database_handle();

my $S = q{Action 'version'};
my $label = 'POSTGRES_VERSION';

$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 MRTG but no option};
like ($cp->run('--output=mrtg'), qr{ERROR: Invalid mrtg}, $t);

$t=qq{$S fails when called with MRTG and a bad argument};
like ($cp->run('--output=mrtg --mrtg=foobar'), qr{ERROR: Invalid mrtg}, $t);

$t=qq{$S fails when called without warning or critical};
like ($cp->run(''), qr{Must provide}, $t);

$t=qq{$S fails when called with invalid warning};
like ($cp->run('-w foo'), qr{ERROR: Invalid string}, $t);

$t=qq{$S fails when called with invalid critical};
like ($cp->run('-c foo'), qr{ERROR: Invalid string}, $t);

$t=qq{$S gives correct output for warning on two-part version};
like ($cp->run('-w 5.2'), qr{^$label WARNING: .+expected 5.2}, $t);

$t=qq{$S gives correct output for warning on three-part version};
like ($cp->run('-w 5.2.1'), qr{^$label WARNING: .+expected 5.2.1}, $t);

$t=qq{$S gives correct output for critical on two-part version};
like ($cp->run('-c 6.10'), qr{^$label CRITICAL: .+expected 6.10}, $t);

$t=qq{$S gives correct output for critical on three-part version};
like ($cp->run('-c 6.10.33'), qr{^$label CRITICAL: .+expected 6.10.33}, $t);

## Now to pull some trickery
$cp->fake_version('foobar');

$t=qq{$S gives correct output on invalid version() parse};
like ($cp->run('-c 8.7'), qr{^$label UNKNOWN: .+Invalid query returned}, $t);

$cp->fake_version('7.8.12');

$t=qq{$S gives correct output for two-part version warning};
like ($cp->run('-w 7.8'), qr{^$label OK: .+version 7.8.12}, $t);

$t=qq{$S gives correct output for two-part version warning};
like ($cp->run('-w 5.8'), qr{^$label WARNING: .+version 7.8.12}, $t);

$t=qq{$S gives correct output for two-part version warning};
like ($cp->run('-w 7.9'), qr{^$label WARNING: .+version 7.8.12}, $t);

$t=qq{$S gives correct output for three-part version warning};
like ($cp->run('-w 7.8.12'), qr{^$label OK: .+version 7.8.12}, $t);

$t=qq{$S gives correct output for three-part version warning};
like ($cp->run('-w 7.8.11'), qr{^$label WARNING: .+version 7.8.12}, $t);

$t=qq{$S gives correct output for matching three-part version warning};
like ($cp->run('-w 7.8.13'), qr{^$label WARNING: .+version 7.8.12}, $t);

$t=qq{$S gives correct output for matching three-part version warning};
like ($cp->run('-w 7.9.13'), qr{^$label WARNING: .+version 7.8.12}, $t);

$t=qq{$S gives correct output for two-part version critical};
like ($cp->run('-c 7.8'), qr{^$label OK: .+version 7.8.12}, $t);

$t=qq{$S gives correct output for two-part version critical};
like ($cp->run('-c 5.8'), qr{^$label CRITICAL: .+version 7.8.12}, $t);

$t=qq{$S gives correct output for two-part version critical};
like ($cp->run('-c 7.9'), qr{^$label CRITICAL: .+version 7.8.12}, $t);

$t=qq{$S gives correct output for three-part version critical};
like ($cp->run('-c 7.8.12'), qr{^$label OK: .+version 7.8.12}, $t);

$t=qq{$S gives correct output for three-part version critical};
like ($cp->run('-c 7.8.11'), qr{^$label CRITICAL: .+version 7.8.12}, $t);

$t=qq{$S gives correct output for matching three-part version critical};
like ($cp->run('-c 7.8.13'), qr{^$label CRITICAL: .+version 7.8.12}, $t);

$t=qq{$S gives correct output for matching three-part version critical};
like ($cp->run('-c 7.9.13'), qr{^$label CRITICAL: .+version 7.8.12}, $t);

$t=qq{$S gives correct output for MRTG output};
like ($cp->run('--output=MRTG --mrtg=7.9.13'), qr{^0\n0\n\n7.8.12\n}, $t);

$t=qq{$S gives correct output for MRTG output};
is ($cp->run('--output=MRTG --mrtg=7.8'), qq{1\n0\n\n7.8.12\n}, $t);

$t=qq{$S gives correct output for MRTG output};
is ($cp->run('--output=MRTG --mrtg=7.8.12'), qq{1\n0\n\n7.8.12\n}, $t);

$cp->drop_schema_if_exists();
$cp->reset_path();

exit;