From e574c6e1d997130d1afbf752111cdd642f5672bd Mon Sep 17 00:00:00 2001 From: Gavin Carr Date: Tue, 26 Sep 2006 04:11:39 +0000 Subject: Add additional Nagios::Plugin tests. git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/Nagios-Plugin/trunk@1484 f882894a-f735-0410-b71e-b25c423dba1c --- t/Nagios-Plugin-01.t | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 t/Nagios-Plugin-01.t (limited to 't/Nagios-Plugin-01.t') diff --git a/t/Nagios-Plugin-01.t b/t/Nagios-Plugin-01.t new file mode 100644 index 0000000..0ae2113 --- /dev/null +++ b/t/Nagios-Plugin-01.t @@ -0,0 +1,51 @@ + +use strict; +use Test::More tests => 12; + +BEGIN { use_ok('Nagios::Plugin') }; + +use Nagios::Plugin::Functions; +Nagios::Plugin::Functions::_fake_exit(1); + +diag "\nusing Nagios::Plugin revision ". $Nagios::Plugin::VERSION . "\n" + if $ENV{TEST_VERBOSE}; + +my $p = Nagios::Plugin->new; +isa_ok( $p, "Nagios::Plugin"); + +$p->shortname("PAGESIZE"); +is($p->shortname, "PAGESIZE", "shortname set correctly"); + +$p = Nagios::Plugin->new; +ok(! defined $p->shortname, "shortname should be unset on new"); + +$p = Nagios::Plugin->new( shortname => "SIZE" ); +is($p->shortname, "SIZE", "shortname set correctly on new"); + +diag "warn if < 10, critical if > 25 " if $ENV{TEST_VERBOSE}; +my $t = $p->set_thresholds( warning => "10:25", critical => "~:25" ); + +$p->add_perfdata( + label => "size", + value => 1, + uom => "kB", + threshold => $t, + ); + +cmp_ok( $p->all_perfoutput, 'eq', "size=1kB;10:25;~:25", "Perfdata correct"); + +my $expected = {qw( + -1 WARNING + 1 WARNING + 20 OK + 25 OK + 26 CRITICAL + 30 CRITICAL + )}; + +foreach (sort {$a<=>$b} keys %$expected) { + like $p->die( return_code => $t->get_status($_), message => "page size at http://... was ${_}kB" ), + qr/$expected->{$_}/, + "Output okay. $_ = $expected->{$_}" ; +} + -- cgit v1.2.3-74-g34f1