From 9d5427f392b4b03b7fd558b4be628653d140f6c0 Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Mon, 17 Mar 2008 20:32:11 +0000 Subject: Fixed parsing of negative values and support full range definitions git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1952 f882894a-f735-0410-b71e-b25c423dba1c --- t/Nagios-Plugin-Performance.t | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 't') diff --git a/t/Nagios-Plugin-Performance.t b/t/Nagios-Plugin-Performance.t index 0574ea0..7a28546 100644 --- a/t/Nagios-Plugin-Performance.t +++ b/t/Nagios-Plugin-Performance.t @@ -1,6 +1,6 @@ use strict; -use Test::More tests => 91; +use Test::More tests => 111; BEGIN { use_ok('Nagios::Plugin::Performance') }; diag "\nusing Nagios::Plugin::Performance revision ". $Nagios::Plugin::Performance::VERSION . "\n" if $ENV{TEST_VERBOSE}; @@ -142,4 +142,33 @@ cmp_ok( $p[0]->uom, "eq", "%", "uom okay"); cmp_ok( $p[0]->threshold->warning, 'eq', "90", "warn okay"); cmp_ok( $p[0]->threshold->critical, 'eq', "95", "crit okay"); +# Check ranges are parsed correctly +@p = Nagios::Plugin::Performance->parse_perfstring("availability=93.8%;90:99;"); +is( $p[0]->label, "availability", "label okay"); +is( $p[0]->value, "93.8", "value okay"); +is( $p[0]->uom, "%", "uom okay"); +ok( defined eval { $p[0]->threshold->warning->is_set }, "Warning range has been set"); +is( $p[0]->threshold->critical->is_set, 0, "Critical range has not been set"); +is( $p[0]->threshold->warning, "90:99", "warn okay"); + +# Check that negative values are parsed correctly in value and ranges +@p = Nagios::Plugin::Performance->parse_perfstring("offset=-0.004476s;-60.000000:-5;-120.000000:-3;"); +is( $p[0]->label, "offset", "label okay"); +is( $p[0]->value, "-0.004476", "value okay"); +is( $p[0]->uom, "s", "uom okay"); +ok( defined eval { $p[0]->threshold->warning->is_set }, "Warning range has been set"); +ok( defined eval { $p[0]->threshold->critical->is_set }, "Critical range has been set"); +is( $p[0]->threshold->warning, "-60:-5", "warn okay"); +is( $p[0]->threshold->critical, "-120:-3", "crit okay"); + +# Check infinity values are okay +@p = Nagios::Plugin::Performance->parse_perfstring("salary=52GBP;~:23;45:"); +is( $p[0]->label, "salary", "label okay"); +is( $p[0]->value, "52", "value okay"); +is( $p[0]->uom, "GBP", "uom okay"); +ok( defined eval { $p[0]->threshold->warning->is_set }, "Warning range has been set"); +is( $p[0]->threshold->critical->is_set, 1, "Critical range has been set"); +is( $p[0]->threshold->warning, "~:23", "warn okay"); +is( $p[0]->threshold->critical, "45:", "warn okay"); + # add_perfdata tests in t/Nagios-Plugin-01.t -- cgit v1.2.3-74-g34f1