[Nagiosplug-checkins] Nagios-Plugin/t Nagios-Plugin-04.t, 1.1, 1.2 Nagios-Plugin-Threshold.t, 1.6, 1.7
Gavin Carr
gonzai at users.sourceforge.net
Fri Mar 16 12:25:17 CET 2007
- Previous message: [Nagiosplug-checkins] Nagios-Plugin Changes, 1.11, 1.12 Makefile.PL, 1.11, 1.12
- Next message: [Nagiosplug-checkins] Nagios-Plugin/lib/Nagios/Plugin Functions.pm, 1.10, 1.11 Performance.pm, 1.11, 1.12 Range.pm, 1.8, 1.9 Threshold.pm, 1.10, 1.11
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/nagiosplug/Nagios-Plugin/t
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv30390/t
Modified Files:
Nagios-Plugin-04.t Nagios-Plugin-Threshold.t
Log Message:
Cleanups, mostly to N::P::Range/Threshold/Performance.
Index: Nagios-Plugin-04.t
===================================================================
RCS file: /cvsroot/nagiosplug/Nagios-Plugin/t/Nagios-Plugin-04.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Nagios-Plugin-04.t 18 Dec 2006 22:45:49 -0000 1.1
+++ Nagios-Plugin-04.t 16 Mar 2007 11:25:15 -0000 1.2
@@ -5,18 +5,20 @@
use strict;
#use Test::More 'no_plan';
use Test::More tests=>26;
-use Test::Exception;
BEGIN { use_ok('Nagios::Plugin') };
use Nagios::Plugin::Functions;
Nagios::Plugin::Functions::_fake_exit(1);
-lives_ok sub { my $broke = Nagios::Plugin->new(); }, "constructor DOESN'T die without usage";
+eval { Nagios::Plugin->new(); };
+ok(! $@, "constructor DOESN'T die without usage");
my $p = Nagios::Plugin->new();
-dies_ok sub { $p->add_arg('warning', 'warning') }, "add_arg() dies if you haven't instantiated with usage";
-dies_ok sub { $p->getopts }, "getopts() dies if you haven't instantiated with usage";
+eval { $p->add_arg('warning', 'warning') };
+ok($@, "add_arg() dies if you haven't instantiated with usage");
+eval { $p->getopts };
+ok($@, "getopts() dies if you haven't instantiated with usage");
$p = Nagios::Plugin->new( usage => "dummy usage statement" );
@@ -41,7 +43,8 @@
#isa_ok $p->threshold, 'Nagios::Plugin::Threshold', "threshold object is defined";
-dies_ok sub { $p->check_threshold() }, "check_threshold dies if called with no args";
+eval { $p->check_threshold() };
+ok($@, "check_threshold dies if called with no args");
# thresholds set implicitly
Index: Nagios-Plugin-Threshold.t
===================================================================
RCS file: /cvsroot/nagiosplug/Nagios-Plugin/t/Nagios-Plugin-Threshold.t,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- Nagios-Plugin-Threshold.t 14 Mar 2007 23:47:23 -0000 1.6
+++ Nagios-Plugin-Threshold.t 16 Mar 2007 11:25:15 -0000 1.7
@@ -1,7 +1,6 @@
use strict;
-use Test::More tests => 71;
-#use Test::Exception; # broken for now so we don't need this.
+use Test::More tests => 87;
BEGIN {
use_ok('Nagios::Plugin::Threshold');
use_ok('Nagios::Plugin::Functions', ':all' );
@@ -37,19 +36,31 @@
my $debug = shift;
foreach (sort {$a<=>$b} keys %$expected) {
- is $STATUS_TEXT{$t->get_status($_)}, $expected->{$_}, " $_ - $expected->{$_}";
- if ($debug) {
- diag "val = $_; critical check = ".$t->critical->check_range($_).
- "; warning check = ".$t->warning->check_range($_);
- }
+ is $STATUS_TEXT{$t->get_status($_)}, $expected->{$_}, " $_ - $expected->{$_}";
+ if ($debug) {
+ diag "val = $_; critical check = ".$t->critical->check_range($_).
+ "; warning check = ".$t->warning->check_range($_);
+ }
}
use Data::Dumper;
diag "thresh dump: ". Dumper $t if $debug;
}
test_expected_statuses( $t, $expected );
+# GMC: this test seems bogus to me - either we've died, in which case internal
+# state is undefined (and untestable!), or we should be returning a non-fatal error
+if (0) {
+ diag "threshold: warn if less than 5 or more than 33." if $ENV{TEST_VERBOSE};
+ eval { $t = Nagios::Plugin::Threshold->set_thresholds(warning => "5:33", critical => "") };
+ ok( defined $t, "Threshold ('5:33', '') set");
+ cmp_ok( $t->warning->start, '==', 5, "Warning start set");
+ cmp_ok( $t->warning->end, '==', 33, "Warning end set");
+ ok( ! $t->critical->is_set, "Critical not set");
+}
+
+# GC: same as previous test, except critical is undef instead of ''
diag "threshold: warn if less than 5 or more than 33." if $ENV{TEST_VERBOSE};
-eval { $t = Nagios::Plugin::Threshold->set_thresholds(warning => "5:33", critical => "") };
+$t = Nagios::Plugin::Threshold->set_thresholds(warning => "5:33", critical => undef);
ok( defined $t, "Threshold ('5:33', '') set");
cmp_ok( $t->warning->start, '==', 5, "Warning start set");
cmp_ok( $t->warning->end, '==', 33, "Warning end set");
@@ -88,7 +99,6 @@
) };
test_expected_statuses( $t, $expected );
-
# "I'm going to die homeless, penniless, and 30 pounds overweight."
# "...and that's...okay."
@@ -163,4 +173,37 @@
) };
test_expected_statuses( $t, $expected );
+
+# GMC: as of 0.16, set_thresholds can also be called as a mutator
+diag "threshold mutator: warn if more than 30; critical if > 60"
+ if $ENV{TEST_VERBOSE};
+my $t1 = $t;
+$t->set_thresholds(warning => "0:45", critical => "0:90");
+is($t1, $t, "same threshold object after \$t->set_thresholds");
+ok( defined $t, "Threshold ('0:45', '0:90') set");
+is( $t->warning->start, 0, "Warning start ok");
+is( $t->warning->end, 45, "Warning end ok");
+is( $t->critical->start, 0, "Critical start ok");
+is( $t->critical->end, 90, "Critical end ok");
+
+
+# Also as of 0.16, accepts N::P::Range objects as arguments
+my $warning = Nagios::Plugin::Range->parse_range_string("50");
+my $critical = Nagios::Plugin::Range->parse_range_string("70:90");
+$t = Nagios::Plugin::Threshold->set_thresholds(warning => $warning, critical => $critical);
+ok( defined $t, "Threshold from ranges ('50', '70:90') set");
+is( $t->warning->start, 0, "Warning start ok");
+is( $t->warning->end, 50, "Warning end ok");
+is( $t->critical->start, 70, "Critical start ok");
+is( $t->critical->end, 90, "Critical end ok");
+
+$critical = Nagios::Plugin::Range->parse_range_string("90:");
+$t->set_thresholds(warning => "~:20", critical => $critical);
+ok( defined $t, "Threshold from string + range ('~:20', '90:') set");
+ok( $t->warning->start_infinity, "Warning start ok (infinity)");
+is( $t->warning->end, 20, "Warning end ok");
+is( $t->critical->start, 90, "Critical start ok");
+ok( $t->critical->end_infinity, "Critical end ok (infinity)");
+
+
ok 1, "sweet, made it to the end.";
- Previous message: [Nagiosplug-checkins] Nagios-Plugin Changes, 1.11, 1.12 Makefile.PL, 1.11, 1.12
- Next message: [Nagiosplug-checkins] Nagios-Plugin/lib/Nagios/Plugin Functions.pm, 1.10, 1.11 Performance.pm, 1.11, 1.12 Range.pm, 1.8, 1.9 Threshold.pm, 1.10, 1.11
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Commits
mailing list