summaryrefslogtreecommitdiffstats
path: root/plugins/t/negate.t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/t/negate.t')
-rw-r--r--plugins/t/negate.t79
1 files changed, 79 insertions, 0 deletions
diff --git a/plugins/t/negate.t b/plugins/t/negate.t
new file mode 100644
index 0000000..0efa0ca
--- /dev/null
+++ b/plugins/t/negate.t
@@ -0,0 +1,79 @@
1#! /usr/bin/perl -w -I ..
2#
3# negate checks
4# Need check_dummy to work for testing
5#
6# $Id: negate.pl 1717 2007-05-24 08:53:50Z tonvoon $
7#
8
9use strict;
10use Test::More;
11use NPTest;
12
13# 47 tests if the "map changes to return codes" patch is applied
14#plan tests => 47;
15plan tests => 15;
16
17my $res;
18
19my $PWD = $ENV{PWD};
20
21$res = NPTest->testCmd( "./negate" );
22is( $res->return_code, 3, "Not enough parameters");
23like( $res->output, "/Could not parse arguments/", "Could not parse arguments");
24
25$res = NPTest->testCmd( "./negate bobthebuilder" );
26is( $res->return_code, 3, "Require full path" );
27like( $res->output, "/Require path to command/", "Appropriate error message");
28
29$res = NPTest->testCmd( "./negate $PWD/check_dummy 0 'a dummy okay'" );
30is( $res->return_code, 2, "OK changed to CRITICAL" );
31is( $res->output, "OK: a dummy okay", "Output as expected" );
32
33$res = NPTest->testCmd( "./negate '$PWD/check_dummy 0 redsweaterblog'");
34is( $res->return_code, 2, "OK => CRIT with a single quote for command to run" );
35is( $res->output, "OK: redsweaterblog", "Output as expected" );
36
37$res = NPTest->testCmd( "./negate $PWD/check_dummy 1 'a warn a day keeps the managers at bay'" );
38is( $res->return_code, 1, "WARN stays same" );
39
40$res = NPTest->testCmd( "./negate $PWD/check_dummy 3 mysterious");
41is( $res->return_code, 3, "UNKNOWN stays same" );
42
43$res = NPTest->testCmd( "./negate \"$PWD/check_dummy 0 'a dummy okay'\"" );
44is( $res->output, "OK: a dummy okay", "Checking slashed quotes - the single quotes are re-evaluated at shell" );
45
46# Output is "OK: a" because check_dummy only returns the first arg
47$res = NPTest->testCmd( "./negate $PWD/check_dummy 0 a dummy okay" );
48is( $res->output, "OK: a", "Multiple args passed as arrays" );
49
50$res = NPTest->testCmd( "./negate $PWD/check_dummy 0 'a dummy okay'" );
51is( $res->output, "OK: a dummy okay", "The quoted string is passed through to subcommand correctly" );
52
53$res = NPTest->testCmd( "./negate '$PWD/check_dummy 0' 'a dummy okay'" );
54is( $res->output, "No data returned from command", "Bad command, as expected (trying to execute './check_dummy 0')");
55
56$res = NPTest->testCmd( './negate $PWD/check_dummy 0 \'$$ a dummy okay\'' );
57is( $res->output, 'OK: $$ a dummy okay', 'Proves that $$ is not being expanded again' );
58
59
60# Remove __DATA__ to run tests with future patch
61__DATA__
62
63TODO: {
64 local $TODO = "Codes can be switched";
65 my %state = (
66 ok => 0,
67 warning => 1,
68 critical => 2,
69 unknown => 3,
70 );
71 foreach my $current_state (qw(ok warning critical unknown)) {
72 foreach my $new_state (qw(ok warning critical unknown)) {
73 $res = NPTest->testCmd( "./negate --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" );
74 is( $res->return_code, $state{$new_state}, "Got fake $new_state" );
75 is( $res->output, uc($current_state).": Fake $new_state" );
76 }
77 }
78}
79