From 7f33b6abe3b5e9ee14de2683f9412ac6641a2fcd Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Sat, 13 Dec 2008 14:05:22 +0000 Subject: 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 --- t/Nagios-Plugin-Performance.t | 55 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 5 deletions(-) (limited to 't') 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 @@ use strict; use Test::More; -BEGIN { use_ok('Nagios::Plugin::Performance') }; - -diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE}; - use Nagios::Plugin::Functions; Nagios::Plugin::Functions::_fake_exit(1); + my (@p, $p); my @test = ( { @@ -19,7 +16,10 @@ my @test = ( }, ); -plan tests => (8 * scalar @test) + 94; +plan tests => (8 * scalar @test) + 125; + +use_ok('Nagios::Plugin::Performance'); +diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE}; # Round-trip tests for my $t (@test) { @@ -72,6 +72,32 @@ ok( ! @p, "Errors correctly"); ok( ! Nagios::Plugin::Performance->parse_perfstring(""), "Errors on empty string"); + +# Check 1 bad with 1 good format output +@p = Nagios::Plugin::Performance->parse_perfstring("rta=&391ms;100,200;500,034;0; pl=0%;20;60 "); +is( scalar @p, 1, "One bad piece of data - only one returned" ); +is( $p[0]->label, "pl", "label okay for different numeric"); +is( $p[0]->value, 0, "value okay"); +is( $p[0]->uom, "%", "uom okay"); +ok( $p[0]->threshold->warning->is_set, "Warning range has been set"); +is( $p[0]->threshold->warning, "20", "warn okay"); +is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); +is( $p[0]->threshold->critical, "60", "warn okay"); + +# Same as above, but order swapped +@p = Nagios::Plugin::Performance->parse_perfstring(" pl=0%;20;60 rta=&391ms;100,200;500,034;0; "); +is( scalar @p, 1, "One bad piece of data - only one returned" ); +is( $p[0]->label, "pl", "label okay for different numeric"); +is( $p[0]->value, 0, "value okay"); +is( $p[0]->uom, "%", "uom okay"); +ok( $p[0]->threshold->warning->is_set, "Warning range has been set"); +is( $p[0]->threshold->warning, "20", "warn okay"); +is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); +is( $p[0]->threshold->critical, "60", "warn okay"); + + + + @p = Nagios::Plugin::Performance->parse_perfstring( "time=0.001229s;0.000000;0.000000;0.000000;10.000000"); 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"); is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); is( $p[0]->threshold->critical, "430:4.3e+25", "warn okay"); + + +# Check different collation with commas instead of periods +@p = Nagios::Plugin::Performance->parse_perfstring("rta=1,391ms;100,200;500,034;0; pl=0%;20;60;;"); +is( $p[0]->label, "rta", "label okay for numeric with commas instead of periods"); +is( $p[0]->value, 1.391, "value okay"); +is( $p[0]->uom, "ms", "uom okay"); +ok( $p[0]->threshold->warning->is_set, "Warning range has been set"); +is( $p[0]->threshold->warning, "100.2", "warn okay"); +is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); +is( $p[0]->threshold->critical, "500.034", "warn okay"); +is( $p[1]->label, "pl", "label okay for different numeric"); +is( $p[1]->value, 0, "value okay"); +is( $p[1]->uom, "%", "uom okay"); +ok( $p[1]->threshold->warning->is_set, "Warning range has been set"); +is( $p[1]->threshold->warning, "20", "warn okay"); +is( $p[1]->threshold->critical->is_set, 1, "Critical range has been set"); +is( $p[1]->threshold->critical, "60", "warn okay"); + # add_perfdata tests in t/Nagios-Plugin-01.t -- cgit v1.2.3-74-g34f1