summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorTon Voon <tonvoon@macbook.local>2008-12-13 14:05:22 (GMT)
committerTon Voon <tonvoon@macbook.local>2008-12-13 14:05:22 (GMT)
commit7f33b6abe3b5e9ee14de2683f9412ac6641a2fcd (patch)
tree3fb9fad68782a1ecdf7ce1814a6b36ffa035145a /t
parent0907cdbca2ebcb775a0bbcae639e378e440cd738 (diff)
downloadmonitoring-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.t55
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
2use strict; 2use strict;
3use Test::More; 3use Test::More;
4BEGIN { use_ok('Nagios::Plugin::Performance') };
5
6diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE};
7
8use Nagios::Plugin::Functions; 4use Nagios::Plugin::Functions;
9Nagios::Plugin::Functions::_fake_exit(1); 5Nagios::Plugin::Functions::_fake_exit(1);
10 6
7
11my (@p, $p); 8my (@p, $p);
12my @test = ( 9my @test = (
13 { 10 {
@@ -19,7 +16,10 @@ my @test = (
19 }, 16 },
20); 17);
21 18
22plan tests => (8 * scalar @test) + 94; 19plan tests => (8 * scalar @test) + 125;
20
21use_ok('Nagios::Plugin::Performance');
22diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE};
23 23
24# Round-trip tests 24# Round-trip tests
25for my $t (@test) { 25for my $t (@test) {
@@ -72,6 +72,32 @@ ok( ! @p, "Errors correctly");
72ok( ! Nagios::Plugin::Performance->parse_perfstring(""), "Errors on empty string"); 72ok( ! 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 ");
78is( scalar @p, 1, "One bad piece of data - only one returned" );
79is( $p[0]->label, "pl", "label okay for different numeric");
80is( $p[0]->value, 0, "value okay");
81is( $p[0]->uom, "%", "uom okay");
82ok( $p[0]->threshold->warning->is_set, "Warning range has been set");
83is( $p[0]->threshold->warning, "20", "warn okay");
84is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set");
85is( $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; ");
89is( scalar @p, 1, "One bad piece of data - only one returned" );
90is( $p[0]->label, "pl", "label okay for different numeric");
91is( $p[0]->value, 0, "value okay");
92is( $p[0]->uom, "%", "uom okay");
93ok( $p[0]->threshold->warning->is_set, "Warning range has been set");
94is( $p[0]->threshold->warning, "20", "warn okay");
95is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set");
96is( $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");
77cmp_ok( $p[0]->label, "eq", "time", "label okay"); 103cmp_ok( $p[0]->label, "eq", "time", "label okay");
@@ -194,4 +220,23 @@ is( $p[0]->threshold->warning, "-1.1e-05:0.001", "warn okay");
194is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); 220is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set");
195is( $p[0]->threshold->critical, "430:4.3e+25", "warn okay"); 221is( $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;;");
227is( $p[0]->label, "rta", "label okay for numeric with commas instead of periods");
228is( $p[0]->value, 1.391, "value okay");
229is( $p[0]->uom, "ms", "uom okay");
230ok( $p[0]->threshold->warning->is_set, "Warning range has been set");
231is( $p[0]->threshold->warning, "100.2", "warn okay");
232is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set");
233is( $p[0]->threshold->critical, "500.034", "warn okay");
234is( $p[1]->label, "pl", "label okay for different numeric");
235is( $p[1]->value, 0, "value okay");
236is( $p[1]->uom, "%", "uom okay");
237ok( $p[1]->threshold->warning->is_set, "Warning range has been set");
238is( $p[1]->threshold->warning, "20", "warn okay");
239is( $p[1]->threshold->critical->is_set, 1, "Critical range has been set");
240is( $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