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