diff options
author | Ton Voon <tonvoon@macbook.local> | 2008-12-13 14:05:22 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@macbook.local> | 2008-12-13 14:05:22 +0000 |
commit | 7f33b6abe3b5e9ee14de2683f9412ac6641a2fcd (patch) | |
tree | 3fb9fad68782a1ecdf7ce1814a6b36ffa035145a /t | |
parent | 0907cdbca2ebcb775a0bbcae639e378e440cd738 (diff) | |
download | monitoring-plugin-perl-7f33b6abe3b5e9ee14de2683f9412ac6641a2fcd.tar.gz |
Fixed parsing of numeric values with commas instead of periods. Fixed test plan
for CPAN test failures of 0.29. Change to parse_perfstring to return back
successfully parsed fields, rather than an empty field, when errors seen
Diffstat (limited to 't')
-rw-r--r-- | t/Nagios-Plugin-Performance.t | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/t/Nagios-Plugin-Performance.t b/t/Nagios-Plugin-Performance.t index ceb82c5..d167979 100644 --- a/t/Nagios-Plugin-Performance.t +++ b/t/Nagios-Plugin-Performance.t | |||
@@ -1,13 +1,10 @@ | |||
1 | 1 | ||
2 | use strict; | 2 | use strict; |
3 | use Test::More; | 3 | use Test::More; |
4 | BEGIN { use_ok('Nagios::Plugin::Performance') }; | ||
5 | |||
6 | diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE}; | ||
7 | |||
8 | use Nagios::Plugin::Functions; | 4 | use Nagios::Plugin::Functions; |
9 | Nagios::Plugin::Functions::_fake_exit(1); | 5 | Nagios::Plugin::Functions::_fake_exit(1); |
10 | 6 | ||
7 | |||
11 | my (@p, $p); | 8 | my (@p, $p); |
12 | my @test = ( | 9 | my @test = ( |
13 | { | 10 | { |
@@ -19,7 +16,10 @@ my @test = ( | |||
19 | }, | 16 | }, |
20 | ); | 17 | ); |
21 | 18 | ||
22 | plan tests => (8 * scalar @test) + 94; | 19 | plan tests => (8 * scalar @test) + 125; |
20 | |||
21 | use_ok('Nagios::Plugin::Performance'); | ||
22 | diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE}; | ||
23 | 23 | ||
24 | # Round-trip tests | 24 | # Round-trip tests |
25 | for my $t (@test) { | 25 | for my $t (@test) { |
@@ -72,6 +72,32 @@ ok( ! @p, "Errors correctly"); | |||
72 | ok( ! Nagios::Plugin::Performance->parse_perfstring(""), "Errors on empty string"); | 72 | ok( ! Nagios::Plugin::Performance->parse_perfstring(""), "Errors on empty string"); |
73 | 73 | ||
74 | 74 | ||
75 | |||
76 | # Check 1 bad with 1 good format output | ||
77 | @p = Nagios::Plugin::Performance->parse_perfstring("rta=&391ms;100,200;500,034;0; pl=0%;20;60 "); | ||
78 | is( scalar @p, 1, "One bad piece of data - only one returned" ); | ||
79 | is( $p[0]->label, "pl", "label okay for different numeric"); | ||
80 | is( $p[0]->value, 0, "value okay"); | ||
81 | is( $p[0]->uom, "%", "uom okay"); | ||
82 | ok( $p[0]->threshold->warning->is_set, "Warning range has been set"); | ||
83 | is( $p[0]->threshold->warning, "20", "warn okay"); | ||
84 | is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); | ||
85 | is( $p[0]->threshold->critical, "60", "warn okay"); | ||
86 | |||
87 | # Same as above, but order swapped | ||
88 | @p = Nagios::Plugin::Performance->parse_perfstring(" pl=0%;20;60 rta=&391ms;100,200;500,034;0; "); | ||
89 | is( scalar @p, 1, "One bad piece of data - only one returned" ); | ||
90 | is( $p[0]->label, "pl", "label okay for different numeric"); | ||
91 | is( $p[0]->value, 0, "value okay"); | ||
92 | is( $p[0]->uom, "%", "uom okay"); | ||
93 | ok( $p[0]->threshold->warning->is_set, "Warning range has been set"); | ||
94 | is( $p[0]->threshold->warning, "20", "warn okay"); | ||
95 | is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); | ||
96 | is( $p[0]->threshold->critical, "60", "warn okay"); | ||
97 | |||
98 | |||
99 | |||
100 | |||
75 | @p = Nagios::Plugin::Performance->parse_perfstring( | 101 | @p = Nagios::Plugin::Performance->parse_perfstring( |
76 | "time=0.001229s;0.000000;0.000000;0.000000;10.000000"); | 102 | "time=0.001229s;0.000000;0.000000;0.000000;10.000000"); |
77 | cmp_ok( $p[0]->label, "eq", "time", "label okay"); | 103 | cmp_ok( $p[0]->label, "eq", "time", "label okay"); |
@@ -194,4 +220,23 @@ is( $p[0]->threshold->warning, "-1.1e-05:0.001", "warn okay"); | |||
194 | is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); | 220 | is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); |
195 | is( $p[0]->threshold->critical, "430:4.3e+25", "warn okay"); | 221 | is( $p[0]->threshold->critical, "430:4.3e+25", "warn okay"); |
196 | 222 | ||
223 | |||
224 | |||
225 | # Check different collation with commas instead of periods | ||
226 | @p = Nagios::Plugin::Performance->parse_perfstring("rta=1,391ms;100,200;500,034;0; pl=0%;20;60;;"); | ||
227 | is( $p[0]->label, "rta", "label okay for numeric with commas instead of periods"); | ||
228 | is( $p[0]->value, 1.391, "value okay"); | ||
229 | is( $p[0]->uom, "ms", "uom okay"); | ||
230 | ok( $p[0]->threshold->warning->is_set, "Warning range has been set"); | ||
231 | is( $p[0]->threshold->warning, "100.2", "warn okay"); | ||
232 | is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); | ||
233 | is( $p[0]->threshold->critical, "500.034", "warn okay"); | ||
234 | is( $p[1]->label, "pl", "label okay for different numeric"); | ||
235 | is( $p[1]->value, 0, "value okay"); | ||
236 | is( $p[1]->uom, "%", "uom okay"); | ||
237 | ok( $p[1]->threshold->warning->is_set, "Warning range has been set"); | ||
238 | is( $p[1]->threshold->warning, "20", "warn okay"); | ||
239 | is( $p[1]->threshold->critical->is_set, 1, "Critical range has been set"); | ||
240 | is( $p[1]->threshold->critical, "60", "warn okay"); | ||
241 | |||
197 | # add_perfdata tests in t/Nagios-Plugin-01.t | 242 | # add_perfdata tests in t/Nagios-Plugin-01.t |