summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/t/negate.pl48
1 files changed, 48 insertions, 0 deletions
diff --git a/plugins/t/negate.pl b/plugins/t/negate.pl
new file mode 100644
index 0000000..6c56d4f
--- /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
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