diff options
Diffstat (limited to 't/Nagios-Plugin-01.t')
| -rw-r--r-- | t/Nagios-Plugin-01.t | 51 |
1 files changed, 51 insertions, 0 deletions
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 @@ | |||
| 1 | |||
| 2 | use strict; | ||
| 3 | use Test::More tests => 12; | ||
| 4 | |||
| 5 | BEGIN { use_ok('Nagios::Plugin') }; | ||
| 6 | |||
| 7 | use Nagios::Plugin::Functions; | ||
| 8 | Nagios::Plugin::Functions::_fake_exit(1); | ||
| 9 | |||
| 10 | diag "\nusing Nagios::Plugin revision ". $Nagios::Plugin::VERSION . "\n" | ||
| 11 | if $ENV{TEST_VERBOSE}; | ||
| 12 | |||
| 13 | my $p = Nagios::Plugin->new; | ||
| 14 | isa_ok( $p, "Nagios::Plugin"); | ||
| 15 | |||
| 16 | $p->shortname("PAGESIZE"); | ||
| 17 | is($p->shortname, "PAGESIZE", "shortname set correctly"); | ||
| 18 | |||
| 19 | $p = Nagios::Plugin->new; | ||
| 20 | ok(! defined $p->shortname, "shortname should be unset on new"); | ||
| 21 | |||
| 22 | $p = Nagios::Plugin->new( shortname => "SIZE" ); | ||
| 23 | is($p->shortname, "SIZE", "shortname set correctly on new"); | ||
| 24 | |||
| 25 | diag "warn if < 10, critical if > 25 " if $ENV{TEST_VERBOSE}; | ||
| 26 | my $t = $p->set_thresholds( warning => "10:25", critical => "~:25" ); | ||
| 27 | |||
| 28 | $p->add_perfdata( | ||
| 29 | label => "size", | ||
| 30 | value => 1, | ||
| 31 | uom => "kB", | ||
| 32 | threshold => $t, | ||
| 33 | ); | ||
| 34 | |||
| 35 | cmp_ok( $p->all_perfoutput, 'eq', "size=1kB;10:25;~:25", "Perfdata correct"); | ||
| 36 | |||
| 37 | my $expected = {qw( | ||
| 38 | -1 WARNING | ||
| 39 | 1 WARNING | ||
| 40 | 20 OK | ||
| 41 | 25 OK | ||
| 42 | 26 CRITICAL | ||
| 43 | 30 CRITICAL | ||
| 44 | )}; | ||
| 45 | |||
| 46 | foreach (sort {$a<=>$b} keys %$expected) { | ||
| 47 | like $p->die( return_code => $t->get_status($_), message => "page size at http://... was ${_}kB" ), | ||
| 48 | qr/$expected->{$_}/, | ||
| 49 | "Output okay. $_ = $expected->{$_}" ; | ||
| 50 | } | ||
| 51 | |||
