From 8a39526e1b8754a8b8fbb50f7f6806af4def7baa Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Fri, 21 Sep 2007 23:01:28 +0000 Subject: 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 --- plugins/t/negate.pl | 48 -------------------------------- plugins/t/negate.t | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 48 deletions(-) delete mode 100644 plugins/t/negate.pl create mode 100644 plugins/t/negate.t (limited to 'plugins/t') 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 @@ -#! /usr/bin/perl -w -I .. -# -# negate checks -# Need check_dummy to work for testing -# -# $Id$ -# - -use strict; -use Test::More; -use NPTest; - -plan tests => 40; - -my $res; - -$res = NPTest->testCmd( "./negate" ); -is( $res->return_code, 3, "Not enough parameters"); -like( $res->output, "/Could not parse arguments/", "Could not parse arguments"); - -$res = NPTest->testCmd( "./negate ./check_dummy 0 'a dummy okay'" ); -is( $res->return_code, 2, "OK changed to CRITICAL" ); -is( $res->output, "OK: a dummy okay" ); - -$res = NPTest->testCmd( "./negate './check_dummy 0 redsweaterblog'"); -is( $res->return_code, 2, "OK => CRIT with a single quote for command to run" ); -is( $res->output, "OK: redsweaterblog" ); - -$res = NPTest->testCmd( "./negate ./check_dummy 1 'a warn a day keeps the managers at bay'" ); -is( $res->return_code, 2, "WARN stays same" ); - -$res = NPTest->testCmd( "./negate ./check_dummy 3 mysterious"); -is( $res->return_code, 3, "UNKNOWN stays same" ); - -my %state = ( - ok => 0, - warning => 1, - critical => 2, - unknown => 3, - ); -foreach my $current_state (qw(ok warning critical unknown)) { - foreach my $new_state (qw(ok warning critical unknown)) { - $res = NPTest->testCmd( "./negate --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" ); - is( $res->return_code, $state{$new_state}, "Got fake $new_state" ); - is( $res->output, uc($current_state).": Fake $new_state" ); - } -} - 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 @@ +#! /usr/bin/perl -w -I .. +# +# negate checks +# Need check_dummy to work for testing +# +# $Id: negate.pl 1717 2007-05-24 08:53:50Z tonvoon $ +# + +use strict; +use Test::More; +use NPTest; + +# 47 tests if the "map changes to return codes" patch is applied +#plan tests => 47; +plan tests => 15; + +my $res; + +my $PWD = $ENV{PWD}; + +$res = NPTest->testCmd( "./negate" ); +is( $res->return_code, 3, "Not enough parameters"); +like( $res->output, "/Could not parse arguments/", "Could not parse arguments"); + +$res = NPTest->testCmd( "./negate bobthebuilder" ); +is( $res->return_code, 3, "Require full path" ); +like( $res->output, "/Require path to command/", "Appropriate error message"); + +$res = NPTest->testCmd( "./negate $PWD/check_dummy 0 'a dummy okay'" ); +is( $res->return_code, 2, "OK changed to CRITICAL" ); +is( $res->output, "OK: a dummy okay", "Output as expected" ); + +$res = NPTest->testCmd( "./negate '$PWD/check_dummy 0 redsweaterblog'"); +is( $res->return_code, 2, "OK => CRIT with a single quote for command to run" ); +is( $res->output, "OK: redsweaterblog", "Output as expected" ); + +$res = NPTest->testCmd( "./negate $PWD/check_dummy 1 'a warn a day keeps the managers at bay'" ); +is( $res->return_code, 1, "WARN stays same" ); + +$res = NPTest->testCmd( "./negate $PWD/check_dummy 3 mysterious"); +is( $res->return_code, 3, "UNKNOWN stays same" ); + +$res = NPTest->testCmd( "./negate \"$PWD/check_dummy 0 'a dummy okay'\"" ); +is( $res->output, "OK: a dummy okay", "Checking slashed quotes - the single quotes are re-evaluated at shell" ); + +# Output is "OK: a" because check_dummy only returns the first arg +$res = NPTest->testCmd( "./negate $PWD/check_dummy 0 a dummy okay" ); +is( $res->output, "OK: a", "Multiple args passed as arrays" ); + +$res = NPTest->testCmd( "./negate $PWD/check_dummy 0 'a dummy okay'" ); +is( $res->output, "OK: a dummy okay", "The quoted string is passed through to subcommand correctly" ); + +$res = NPTest->testCmd( "./negate '$PWD/check_dummy 0' 'a dummy okay'" ); +is( $res->output, "No data returned from command", "Bad command, as expected (trying to execute './check_dummy 0')"); + +$res = NPTest->testCmd( './negate $PWD/check_dummy 0 \'$$ a dummy okay\'' ); +is( $res->output, 'OK: $$ a dummy okay', 'Proves that $$ is not being expanded again' ); + + +# Remove __DATA__ to run tests with future patch +__DATA__ + +TODO: { + local $TODO = "Codes can be switched"; + my %state = ( + ok => 0, + warning => 1, + critical => 2, + unknown => 3, + ); + foreach my $current_state (qw(ok warning critical unknown)) { + foreach my $new_state (qw(ok warning critical unknown)) { + $res = NPTest->testCmd( "./negate --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" ); + is( $res->return_code, $state{$new_state}, "Got fake $new_state" ); + is( $res->output, uc($current_state).": Fake $new_state" ); + } + } +} + -- cgit v1.2.3