diff options
author | Gavin Carr <gonzai@users.sourceforge.net> | 2007-03-16 11:25:15 +0000 |
---|---|---|
committer | Gavin Carr <gonzai@users.sourceforge.net> | 2007-03-16 11:25:15 +0000 |
commit | c6cbf050974c8f6642fa1d7bde309710b66cbfa0 (patch) | |
tree | 0eb0ea62814b0623fb619c2af3287a585de48c2c /t/Nagios-Plugin-Threshold.t | |
parent | e5109f99c9657a1a8e9fb32b19254a417e2ccd65 (diff) | |
download | monitoring-plugin-perl-c6cbf050974c8f6642fa1d7bde309710b66cbfa0.tar.gz |
Cleanups, mostly to N::P::Range/Threshold/Performance.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1641 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 't/Nagios-Plugin-Threshold.t')
-rw-r--r-- | t/Nagios-Plugin-Threshold.t | 61 |
1 files changed, 52 insertions, 9 deletions
diff --git a/t/Nagios-Plugin-Threshold.t b/t/Nagios-Plugin-Threshold.t index ccb53eb..d3711bb 100644 --- a/t/Nagios-Plugin-Threshold.t +++ b/t/Nagios-Plugin-Threshold.t | |||
@@ -1,7 +1,6 @@ | |||
1 | 1 | ||
2 | use strict; | 2 | use strict; |
3 | use Test::More tests => 71; | 3 | use Test::More tests => 87; |
4 | #use Test::Exception; # broken for now so we don't need this. | ||
5 | BEGIN { | 4 | BEGIN { |
6 | use_ok('Nagios::Plugin::Threshold'); | 5 | use_ok('Nagios::Plugin::Threshold'); |
7 | use_ok('Nagios::Plugin::Functions', ':all' ); | 6 | use_ok('Nagios::Plugin::Functions', ':all' ); |
@@ -37,19 +36,31 @@ sub test_expected_statuses { | |||
37 | my $debug = shift; | 36 | my $debug = shift; |
38 | 37 | ||
39 | foreach (sort {$a<=>$b} keys %$expected) { | 38 | foreach (sort {$a<=>$b} keys %$expected) { |
40 | is $STATUS_TEXT{$t->get_status($_)}, $expected->{$_}, " $_ - $expected->{$_}"; | 39 | is $STATUS_TEXT{$t->get_status($_)}, $expected->{$_}, " $_ - $expected->{$_}"; |
41 | if ($debug) { | 40 | if ($debug) { |
42 | diag "val = $_; critical check = ".$t->critical->check_range($_). | 41 | diag "val = $_; critical check = ".$t->critical->check_range($_). |
43 | "; warning check = ".$t->warning->check_range($_); | 42 | "; warning check = ".$t->warning->check_range($_); |
44 | } | 43 | } |
45 | } | 44 | } |
46 | use Data::Dumper; | 45 | use Data::Dumper; |
47 | diag "thresh dump: ". Dumper $t if $debug; | 46 | diag "thresh dump: ". Dumper $t if $debug; |
48 | } | 47 | } |
49 | test_expected_statuses( $t, $expected ); | 48 | test_expected_statuses( $t, $expected ); |
50 | 49 | ||
50 | # GMC: this test seems bogus to me - either we've died, in which case internal | ||
51 | # state is undefined (and untestable!), or we should be returning a non-fatal error | ||
52 | if (0) { | ||
53 | diag "threshold: warn if less than 5 or more than 33." if $ENV{TEST_VERBOSE}; | ||
54 | eval { $t = Nagios::Plugin::Threshold->set_thresholds(warning => "5:33", critical => "") }; | ||
55 | ok( defined $t, "Threshold ('5:33', '') set"); | ||
56 | cmp_ok( $t->warning->start, '==', 5, "Warning start set"); | ||
57 | cmp_ok( $t->warning->end, '==', 33, "Warning end set"); | ||
58 | ok( ! $t->critical->is_set, "Critical not set"); | ||
59 | } | ||
60 | |||
61 | # GC: same as previous test, except critical is undef instead of '' | ||
51 | diag "threshold: warn if less than 5 or more than 33." if $ENV{TEST_VERBOSE}; | 62 | diag "threshold: warn if less than 5 or more than 33." if $ENV{TEST_VERBOSE}; |
52 | eval { $t = Nagios::Plugin::Threshold->set_thresholds(warning => "5:33", critical => "") }; | 63 | $t = Nagios::Plugin::Threshold->set_thresholds(warning => "5:33", critical => undef); |
53 | ok( defined $t, "Threshold ('5:33', '') set"); | 64 | ok( defined $t, "Threshold ('5:33', '') set"); |
54 | cmp_ok( $t->warning->start, '==', 5, "Warning start set"); | 65 | cmp_ok( $t->warning->start, '==', 5, "Warning start set"); |
55 | cmp_ok( $t->warning->end, '==', 33, "Warning end set"); | 66 | cmp_ok( $t->warning->end, '==', 33, "Warning end set"); |
@@ -88,7 +99,6 @@ $expected = { qw( | |||
88 | ) }; | 99 | ) }; |
89 | test_expected_statuses( $t, $expected ); | 100 | test_expected_statuses( $t, $expected ); |
90 | 101 | ||
91 | |||
92 | # "I'm going to die homeless, penniless, and 30 pounds overweight." | 102 | # "I'm going to die homeless, penniless, and 30 pounds overweight." |
93 | # "...and that's...okay." | 103 | # "...and that's...okay." |
94 | 104 | ||
@@ -163,4 +173,37 @@ $expected = { qw( | |||
163 | ) }; | 173 | ) }; |
164 | test_expected_statuses( $t, $expected ); | 174 | test_expected_statuses( $t, $expected ); |
165 | 175 | ||
176 | |||
177 | # GMC: as of 0.16, set_thresholds can also be called as a mutator | ||
178 | diag "threshold mutator: warn if more than 30; critical if > 60" | ||
179 | if $ENV{TEST_VERBOSE}; | ||
180 | my $t1 = $t; | ||
181 | $t->set_thresholds(warning => "0:45", critical => "0:90"); | ||
182 | is($t1, $t, "same threshold object after \$t->set_thresholds"); | ||
183 | ok( defined $t, "Threshold ('0:45', '0:90') set"); | ||
184 | is( $t->warning->start, 0, "Warning start ok"); | ||
185 | is( $t->warning->end, 45, "Warning end ok"); | ||
186 | is( $t->critical->start, 0, "Critical start ok"); | ||
187 | is( $t->critical->end, 90, "Critical end ok"); | ||
188 | |||
189 | |||
190 | # Also as of 0.16, accepts N::P::Range objects as arguments | ||
191 | my $warning = Nagios::Plugin::Range->parse_range_string("50"); | ||
192 | my $critical = Nagios::Plugin::Range->parse_range_string("70:90"); | ||
193 | $t = Nagios::Plugin::Threshold->set_thresholds(warning => $warning, critical => $critical); | ||
194 | ok( defined $t, "Threshold from ranges ('50', '70:90') set"); | ||
195 | is( $t->warning->start, 0, "Warning start ok"); | ||
196 | is( $t->warning->end, 50, "Warning end ok"); | ||
197 | is( $t->critical->start, 70, "Critical start ok"); | ||
198 | is( $t->critical->end, 90, "Critical end ok"); | ||
199 | |||
200 | $critical = Nagios::Plugin::Range->parse_range_string("90:"); | ||
201 | $t->set_thresholds(warning => "~:20", critical => $critical); | ||
202 | ok( defined $t, "Threshold from string + range ('~:20', '90:') set"); | ||
203 | ok( $t->warning->start_infinity, "Warning start ok (infinity)"); | ||
204 | is( $t->warning->end, 20, "Warning end ok"); | ||
205 | is( $t->critical->start, 90, "Critical start ok"); | ||
206 | ok( $t->critical->end_infinity, "Critical end ok (infinity)"); | ||
207 | |||
208 | |||
166 | ok 1, "sweet, made it to the end."; | 209 | ok 1, "sweet, made it to the end."; |