diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2007-09-21 23:01:28 (GMT) |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2007-09-21 23:01:28 (GMT) |
commit | 8a39526e1b8754a8b8fbb50f7f6806af4def7baa (patch) | |
tree | c80f8ddafe75a920cdcec549e30e728bb57125f9 /plugins/t/negate.t | |
parent | 7a7052512953e6626edf8efc87664dba3ee01d74 (diff) | |
download | monitoring-plugins-8a39526e1b8754a8b8fbb50f7f6806af4def7baa.tar.gz |
Stop double expansion of parameters for negate - works like
time command now
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1784 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/t/negate.t')
-rw-r--r-- | plugins/t/negate.t | 79 |
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 | |||
9 | use strict; | ||
10 | use Test::More; | ||
11 | use NPTest; | ||
12 | |||
13 | # 47 tests if the "map changes to return codes" patch is applied | ||
14 | #plan tests => 47; | ||
15 | plan tests => 15; | ||
16 | |||
17 | my $res; | ||
18 | |||
19 | my $PWD = $ENV{PWD}; | ||
20 | |||
21 | $res = NPTest->testCmd( "./negate" ); | ||
22 | is( $res->return_code, 3, "Not enough parameters"); | ||
23 | like( $res->output, "/Could not parse arguments/", "Could not parse arguments"); | ||
24 | |||
25 | $res = NPTest->testCmd( "./negate bobthebuilder" ); | ||
26 | is( $res->return_code, 3, "Require full path" ); | ||
27 | like( $res->output, "/Require path to command/", "Appropriate error message"); | ||
28 | |||
29 | $res = NPTest->testCmd( "./negate $PWD/check_dummy 0 'a dummy okay'" ); | ||
30 | is( $res->return_code, 2, "OK changed to CRITICAL" ); | ||
31 | is( $res->output, "OK: a dummy okay", "Output as expected" ); | ||
32 | |||
33 | $res = NPTest->testCmd( "./negate '$PWD/check_dummy 0 redsweaterblog'"); | ||
34 | is( $res->return_code, 2, "OK => CRIT with a single quote for command to run" ); | ||
35 | is( $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'" ); | ||
38 | is( $res->return_code, 1, "WARN stays same" ); | ||
39 | |||
40 | $res = NPTest->testCmd( "./negate $PWD/check_dummy 3 mysterious"); | ||
41 | is( $res->return_code, 3, "UNKNOWN stays same" ); | ||
42 | |||
43 | $res = NPTest->testCmd( "./negate \"$PWD/check_dummy 0 'a dummy okay'\"" ); | ||
44 | is( $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" ); | ||
48 | is( $res->output, "OK: a", "Multiple args passed as arrays" ); | ||
49 | |||
50 | $res = NPTest->testCmd( "./negate $PWD/check_dummy 0 'a dummy okay'" ); | ||
51 | is( $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'" ); | ||
54 | is( $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\'' ); | ||
57 | is( $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 | |||
63 | TODO: { | ||
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 | |||