diff options
Diffstat (limited to 'plugins/t/negate.pl')
-rw-r--r-- | plugins/t/negate.pl | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/plugins/t/negate.pl b/plugins/t/negate.pl new file mode 100644 index 00000000..6c56d4f4 --- /dev/null +++ b/plugins/t/negate.pl | |||
@@ -0,0 +1,48 @@ | |||
1 | #! /usr/bin/perl -w -I .. | ||
2 | # | ||
3 | # negate checks | ||
4 | # Need check_dummy to work for testing | ||
5 | # | ||
6 | # $Id$ | ||
7 | # | ||
8 | |||
9 | use strict; | ||
10 | use Test::More; | ||
11 | use NPTest; | ||
12 | |||
13 | plan tests => 40; | ||
14 | |||
15 | my $res; | ||
16 | |||
17 | $res = NPTest->testCmd( "./negate" ); | ||
18 | is( $res->return_code, 3, "Not enough parameters"); | ||
19 | like( $res->output, "/Could not parse arguments/", "Could not parse arguments"); | ||
20 | |||
21 | $res = NPTest->testCmd( "./negate ./check_dummy 0 'a dummy okay'" ); | ||
22 | is( $res->return_code, 2, "OK changed to CRITICAL" ); | ||
23 | is( $res->output, "OK: a dummy okay" ); | ||
24 | |||
25 | $res = NPTest->testCmd( "./negate './check_dummy 0 redsweaterblog'"); | ||
26 | is( $res->return_code, 2, "OK => CRIT with a single quote for command to run" ); | ||
27 | is( $res->output, "OK: redsweaterblog" ); | ||
28 | |||
29 | $res = NPTest->testCmd( "./negate ./check_dummy 1 'a warn a day keeps the managers at bay'" ); | ||
30 | is( $res->return_code, 2, "WARN stays same" ); | ||
31 | |||
32 | $res = NPTest->testCmd( "./negate ./check_dummy 3 mysterious"); | ||
33 | is( $res->return_code, 3, "UNKNOWN stays same" ); | ||
34 | |||
35 | my %state = ( | ||
36 | ok => 0, | ||
37 | warning => 1, | ||
38 | critical => 2, | ||
39 | unknown => 3, | ||
40 | ); | ||
41 | foreach my $current_state (qw(ok warning critical unknown)) { | ||
42 | foreach my $new_state (qw(ok warning critical unknown)) { | ||
43 | $res = NPTest->testCmd( "./negate --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" ); | ||
44 | is( $res->return_code, $state{$new_state}, "Got fake $new_state" ); | ||
45 | is( $res->output, uc($current_state).": Fake $new_state" ); | ||
46 | } | ||
47 | } | ||
48 | |||