summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorGavin Carr <gonzai@users.sourceforge.net>2007-03-14 23:47:23 (GMT)
committerGavin Carr <gonzai@users.sourceforge.net>2007-03-14 23:47:23 (GMT)
commite5109f99c9657a1a8e9fb32b19254a417e2ccd65 (patch)
tree2fdbad42f466051ffc2e332cf0a2573976e3a56c /t
parent489df48f9d1891b46ae4be911080ab4667058f2d (diff)
downloadmonitoring-plugin-perl-e5109f99c9657a1a8e9fb32b19254a417e2ccd65.tar.gz
Refactor N::P::Performance; cleanups to Threshold and Range (mostly perldocs).
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1640 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 't')
-rw-r--r--t/Nagios-Plugin-Performance.t48
-rw-r--r--t/Nagios-Plugin-Threshold.t2
2 files changed, 45 insertions, 5 deletions
diff --git a/t/Nagios-Plugin-Performance.t b/t/Nagios-Plugin-Performance.t
index 1ae330a..0dcb800 100644
--- a/t/Nagios-Plugin-Performance.t
+++ b/t/Nagios-Plugin-Performance.t
@@ -1,6 +1,6 @@
1 1
2use strict; 2use strict;
3use Test::More tests => 49; 3use Test::More tests => 77;
4BEGIN { use_ok('Nagios::Plugin::Performance') }; 4BEGIN { use_ok('Nagios::Plugin::Performance') };
5 5
6diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE}; 6diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE};
@@ -8,15 +8,55 @@ diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performan
8use Nagios::Plugin::Functions; 8use Nagios::Plugin::Functions;
9Nagios::Plugin::Functions::_fake_exit(1); 9Nagios::Plugin::Functions::_fake_exit(1);
10 10
11my @p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448"); 11my (@p, $p);
12my @test = (
13 {
14 perfoutput => "/=382MB;15264;15269;0;32768", label => '/', rrdlabel => 'root', value => 382, uom => 'MB', warning => 15264, critical => 15269, min => 0, max => 32768,
15 }, {
16 perfoutput => "/var=218MB;9443;9448", label => '/var', rrdlabel => 'var', value => '218', uom => 'MB', warning => 9443, critical => 9448, min => undef, max => undef,
17 },
18);
19
20# Round-trip tests
21for my $t (@test) {
22 # Parse to components
23 ($p) = Nagios::Plugin::Performance->parse_perfstring($t->{perfoutput});
24 for (sort keys %$t) {
25 next if m/^perfoutput$/;
26 is($p->$_(), $t->{$_}, "$_ okay (" . (defined $t->{$_} ? $t->{$_} : 'undef') . ")");
27 }
28
29 # Construct from components
30 my @construct = qw(label value uom warning critical min max);
31 $p = Nagios::Plugin::Performance->new(map { $_ => $t->{$_} } @construct);
32 is($p->perfoutput, $t->{perfoutput}, "perfoutput okay ($t->{perfoutput})");
33 # Check threshold accessor
34 is($p->threshold->warning->end, $t->{warning}, "threshold warning okay ($t->{warning})");
35 is($p->threshold->critical->end, $t->{critical}, "threshold critical okay ($t->{critical})");
36
37 # Construct using threshold
38 @construct = qw(label value uom min max);
39 $p = Nagios::Plugin::Performance->new(
40 map({ $_ => $t->{$_} } @construct),
41 threshold => Nagios::Plugin::Threshold->set_thresholds(warning => $t->{warning}, critical => $t->{critical}),
42 );
43 is($p->perfoutput, $t->{perfoutput}, "perfoutput okay ($t->{perfoutput})");
44 # Check warning/critical accessors
45 is($p->warning, $t->{warning}, "warning okay ($t->{warning})");
46 is($p->critical, $t->{critical}, "critical okay ($t->{critical})");
47}
48
49
50# Test multiple parse_perfstrings
51@p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448");
12cmp_ok( $p[0]->label, 'eq', "/", "label okay"); 52cmp_ok( $p[0]->label, 'eq', "/", "label okay");
13cmp_ok( $p[0]->rrdlabel, 'eq', "root", "rrd label okay"); 53cmp_ok( $p[0]->rrdlabel, 'eq', "root", "rrd label okay");
14cmp_ok( $p[0]->value, '==', 382, "value okay"); 54cmp_ok( $p[0]->value, '==', 382, "value okay");
15cmp_ok( $p[0]->uom, 'eq', "MB", "uom okay"); 55cmp_ok( $p[0]->uom, 'eq', "MB", "uom okay");
16cmp_ok( $p[0]->threshold->warning->end, "==", 15264, "warn okay"); 56cmp_ok( $p[0]->threshold->warning->end, "==", 15264, "warn okay");
17cmp_ok( $p[0]->threshold->critical->end, "==", 15269, "crit okay"); 57cmp_ok( $p[0]->threshold->critical->end, "==", 15269, "crit okay");
18ok( ! defined $p[0]->min, "min okay"); 58ok(! defined $p[0]->min, "min undef");
19ok( ! defined $p[0]->max, "max okay"); 59ok(! defined $p[0]->max, "max undef");
20 60
21cmp_ok( $p[1]->label, 'eq', "/var", "label okay"); 61cmp_ok( $p[1]->label, 'eq', "/var", "label okay");
22cmp_ok( $p[1]->rrdlabel, 'eq', "var", "rrd label okay"); 62cmp_ok( $p[1]->rrdlabel, 'eq', "var", "rrd label okay");
diff --git a/t/Nagios-Plugin-Threshold.t b/t/Nagios-Plugin-Threshold.t
index cdb8d77..ccb53eb 100644
--- a/t/Nagios-Plugin-Threshold.t
+++ b/t/Nagios-Plugin-Threshold.t
@@ -113,7 +113,7 @@ SKIP_DEATH:
113 113
114diag "threshold: critical if > 25 " if $ENV{TEST_VERBOSE}; 114diag "threshold: critical if > 25 " if $ENV{TEST_VERBOSE};
115$t = Nagios::Plugin::Threshold->set_thresholds( critical => "~:25" ); 115$t = Nagios::Plugin::Threshold->set_thresholds( critical => "~:25" );
116ok( defined $t, "Threshold ('', '~:25') set (".$t->critical->stringify().")" ); 116ok( defined $t, "Threshold ('', '~:25') set (".$t->critical.")" );
117ok( ! $t->warning->is_set, "Warning not set"); 117ok( ! $t->warning->is_set, "Warning not set");
118cmp_ok( $t->critical->end, '==',25, "Critical end set"); 118cmp_ok( $t->critical->end, '==',25, "Critical end set");
119ok $t->critical->start_infinity, "Critical starts at negative infinity"; 119ok $t->critical->start_infinity, "Critical starts at negative infinity";