update changelog
[monitoring-plugin-perl.git] / t / check_stuff.t
blob6a1d8454d61dcdf5e3b6b5f0f6179ad363baea31
1 #!/usr/local/bin/perl
3 use strict; use warnings;
4 #use Test::More qw(no_plan);
5 use Test::More tests => 14;
7 my ($r,$args);
8 my $s = 't/check_stuff.pl';
9 $s = "$^X -Ilib $s";
11 my $n = 'STUFF';
13 # Monitoring status strings and exit codes
14 my %e = qw(
15 OK 0
16 WARNING 1
17 CRITICAL 2
18 UNKNOWN 3
21 $r = `$s`;
22 is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with no args";
23 like $r, qr/^$n UNKNOWN/, "UNKNOWN with no args";
25 $r = `$s -V`;
26 is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with -V arg";
27 like $r, qr/^[\w\.]+ \d+/i, "looks like there's a version";
29 $r = `$s -h`;
30 is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with -h arg";
31 like $r, qr/usage/i, "looks like there's something helpful"; # broken
33 $args = " -r 99 ";
34 diag "running `$s $args`" if $ENV{TEST_VERBOSE};
35 $r = `$s $args`;
36 diag "output: '$r'" if $ENV{TEST_VERBOSE};
37 is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with $args";
38 like $r, qr/UNKNOWN.+invalid/i, "UNKNOWN (warning: invalid -r) with $args";
41 my $expected = {
42 " -w 10:15 -c~:15 -r 0" => 'WARNING',
43 " -w 10:15 -c~:15 -r 11" => 'OK',
44 " -w 10:15 -c~:15 -r 15.8" => 'CRITICAL',
47 test_expected( $s, $expected );
50 sub test_expected {
51 my $s = shift;
52 my $expected = shift;
53 foreach ( keys %$expected ) {
54 diag "running `$s $_`" if $ENV{TEST_VERBOSE};
55 $r = `$s $_`;
56 diag "output: '$r'" if $ENV{TEST_VERBOSE};
57 is $?>>8 , $e{$expected->{$_}}, "exits($e{$expected->{$_}}) with $_";
58 like $r, qr/^$n $expected->{$_}/i, "looks $expected->{$_} with $_";