diff options
Diffstat (limited to 't/check_stuff.t')
-rwxr-xr-x | t/check_stuff.t | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/t/check_stuff.t b/t/check_stuff.t new file mode 100755 index 0000000..a748605 --- /dev/null +++ b/t/check_stuff.t | |||
@@ -0,0 +1,76 @@ | |||
1 | #!/usr/local/bin/perl | ||
2 | # | ||
3 | use strict; use warnings; | ||
4 | #use Test::More qw(no_plan); | ||
5 | use Test::More tests => 16; | ||
6 | |||
7 | my ($r,$args); | ||
8 | my $s = 't/check_stuff.pl'; | ||
9 | $s = 'perl -Ilib '.$s; | ||
10 | |||
11 | my $n = 'CHECK_STUFF'; | ||
12 | |||
13 | # Nagios status strings and exit codes | ||
14 | my %e = qw( | ||
15 | OK 0 | ||
16 | WARNING 1 | ||
17 | CRITICAL 2 | ||
18 | UNKNOWN 3 | ||
19 | ); | ||
20 | |||
21 | $r = `$s`; | ||
22 | is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with no args"; | ||
23 | like $r, qr/^$n UNKNOWN/, "UNKNOWN with no args"; | ||
24 | |||
25 | |||
26 | #TODO: | ||
27 | SKIP: { | ||
28 | local $TODO = q~d'oh! we'll have to redirect STDERR and check it with like() here instead of checking `` which only gets STDIN. Maybe use IPC::Open3?~; | ||
29 | skip "too noisy, see TODO here", 6; | ||
30 | |||
31 | $r = `$s -V`; | ||
32 | is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with -V arg"; | ||
33 | like $r, qr/\d+\.\d/i, "looks like there's a version"; # broken | ||
34 | is $r, '', "prints nothing to STDOUT"; | ||
35 | |||
36 | $r = `$s -h`; | ||
37 | is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with -h arg"; | ||
38 | like $r, qr/usage/i, "looks like there's something helpful"; # broken | ||
39 | is $r, '', "prints nothing to STDOUT"; | ||
40 | } | ||
41 | |||
42 | |||
43 | $args = " -r 99 "; | ||
44 | diag "running `$s $args`" if $ENV{TEST_VERBOSE}; | ||
45 | $r = `$s $args`; | ||
46 | diag "output: '$r'" if $ENV{TEST_VERBOSE}; | ||
47 | is $?>>8 , $e{UNKNOWN}, "exits($e{UNKNOWN}) with $args"; | ||
48 | like $r, qr/UNKNOWN.+invalid/i, "UNKNOWN (warning: invalid -r) with $args"; | ||
49 | |||
50 | |||
51 | my $expected = { | ||
52 | " -w 10:15 -c~:15 -r 0" => 'WARNING', | ||
53 | " -w 10:15 -c~:15 -r 11" => 'OK', | ||
54 | " -w 10:15 -c~:15 -r 15.8" => 'CRITICAL', | ||
55 | }; | ||
56 | |||
57 | test_expected( $s, $expected ); | ||
58 | |||
59 | |||
60 | sub test_expected { | ||
61 | my $s = shift; | ||
62 | my $expected = shift; | ||
63 | foreach ( keys %$expected ) { | ||
64 | diag "running `$s $_`" if $ENV{TEST_VERBOSE}; | ||
65 | $r = `$s $_`; | ||
66 | diag "output: '$r'" if $ENV{TEST_VERBOSE}; | ||
67 | is $?>>8 , $e{$expected->{$_}}, "exits($e{$expected->{$_}}) with $_"; | ||
68 | like $r, qr/^$n $expected->{$_}/i, "looks $expected->{$_} with $_"; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | |||
73 | |||
74 | |||
75 | |||
76 | |||