summaryrefslogtreecommitdiffstats
path: root/plugins/t
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2007-09-21 23:01:28 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2007-09-21 23:01:28 +0000
commit8a39526e1b8754a8b8fbb50f7f6806af4def7baa (patch)
treec80f8ddafe75a920cdcec549e30e728bb57125f9 /plugins/t
parent7a7052512953e6626edf8efc87664dba3ee01d74 (diff)
downloadmonitoring-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')
-rw-r--r--plugins/t/negate.pl48
-rw-r--r--plugins/t/negate.t79
2 files changed, 79 insertions, 48 deletions
diff --git a/plugins/t/negate.pl b/plugins/t/negate.pl
deleted file mode 100644
index 6c56d4f4..00000000
--- a/plugins/t/negate.pl
+++ /dev/null
@@ -1,48 +0,0 @@
1#! /usr/bin/perl -w -I ..
2#
3# negate checks
4# Need check_dummy to work for testing
5#
6# $Id$
7#
8
9use strict;
10use Test::More;
11use NPTest;
12
13plan tests => 40;
14
15my $res;
16
17$res = NPTest->testCmd( "./negate" );
18is( $res->return_code, 3, "Not enough parameters");
19like( $res->output, "/Could not parse arguments/", "Could not parse arguments");
20
21$res = NPTest->testCmd( "./negate ./check_dummy 0 'a dummy okay'" );
22is( $res->return_code, 2, "OK changed to CRITICAL" );
23is( $res->output, "OK: a dummy okay" );
24
25$res = NPTest->testCmd( "./negate './check_dummy 0 redsweaterblog'");
26is( $res->return_code, 2, "OK => CRIT with a single quote for command to run" );
27is( $res->output, "OK: redsweaterblog" );
28
29$res = NPTest->testCmd( "./negate ./check_dummy 1 'a warn a day keeps the managers at bay'" );
30is( $res->return_code, 2, "WARN stays same" );
31
32$res = NPTest->testCmd( "./negate ./check_dummy 3 mysterious");
33is( $res->return_code, 3, "UNKNOWN stays same" );
34
35my %state = (
36 ok => 0,
37 warning => 1,
38 critical => 2,
39 unknown => 3,
40 );
41foreach 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
diff --git a/plugins/t/negate.t b/plugins/t/negate.t
new file mode 100644
index 00000000..0efa0ca8
--- /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