diff options
author | Gavin Carr <gonzai@users.sourceforge.net> | 2007-03-14 23:47:23 +0000 |
---|---|---|
committer | Gavin Carr <gonzai@users.sourceforge.net> | 2007-03-14 23:47:23 +0000 |
commit | e5109f99c9657a1a8e9fb32b19254a417e2ccd65 (patch) | |
tree | 2fdbad42f466051ffc2e332cf0a2573976e3a56c /t/Nagios-Plugin-Performance.t | |
parent | 489df48f9d1891b46ae4be911080ab4667058f2d (diff) | |
download | monitoring-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/Nagios-Plugin-Performance.t')
-rw-r--r-- | t/Nagios-Plugin-Performance.t | 48 |
1 files changed, 44 insertions, 4 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 | ||
2 | use strict; | 2 | use strict; |
3 | use Test::More tests => 49; | 3 | use Test::More tests => 77; |
4 | BEGIN { use_ok('Nagios::Plugin::Performance') }; | 4 | BEGIN { use_ok('Nagios::Plugin::Performance') }; |
5 | 5 | ||
6 | diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE}; | 6 | diag "\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 | |||
8 | use Nagios::Plugin::Functions; | 8 | use Nagios::Plugin::Functions; |
9 | Nagios::Plugin::Functions::_fake_exit(1); | 9 | Nagios::Plugin::Functions::_fake_exit(1); |
10 | 10 | ||
11 | my @p = Nagios::Plugin::Performance->parse_perfstring("/=382MB;15264;15269;; /var=218MB;9443;9448"); | 11 | my (@p, $p); |
12 | my @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 | ||
21 | for 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"); | ||
12 | cmp_ok( $p[0]->label, 'eq', "/", "label okay"); | 52 | cmp_ok( $p[0]->label, 'eq', "/", "label okay"); |
13 | cmp_ok( $p[0]->rrdlabel, 'eq', "root", "rrd label okay"); | 53 | cmp_ok( $p[0]->rrdlabel, 'eq', "root", "rrd label okay"); |
14 | cmp_ok( $p[0]->value, '==', 382, "value okay"); | 54 | cmp_ok( $p[0]->value, '==', 382, "value okay"); |
15 | cmp_ok( $p[0]->uom, 'eq', "MB", "uom okay"); | 55 | cmp_ok( $p[0]->uom, 'eq', "MB", "uom okay"); |
16 | cmp_ok( $p[0]->threshold->warning->end, "==", 15264, "warn okay"); | 56 | cmp_ok( $p[0]->threshold->warning->end, "==", 15264, "warn okay"); |
17 | cmp_ok( $p[0]->threshold->critical->end, "==", 15269, "crit okay"); | 57 | cmp_ok( $p[0]->threshold->critical->end, "==", 15269, "crit okay"); |
18 | ok( ! defined $p[0]->min, "min okay"); | 58 | ok(! defined $p[0]->min, "min undef"); |
19 | ok( ! defined $p[0]->max, "max okay"); | 59 | ok(! defined $p[0]->max, "max undef"); |
20 | 60 | ||
21 | cmp_ok( $p[1]->label, 'eq', "/var", "label okay"); | 61 | cmp_ok( $p[1]->label, 'eq', "/var", "label okay"); |
22 | cmp_ok( $p[1]->rrdlabel, 'eq', "var", "rrd label okay"); | 62 | cmp_ok( $p[1]->rrdlabel, 'eq', "var", "rrd label okay"); |