summaryrefslogtreecommitdiffstats
path: root/plugins/t/negate.t
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@aei.ca>2009-03-20 06:28:02 (GMT)
committerThomas Guyot-Sionnest <dermoth@aei.ca>2009-03-20 06:28:02 (GMT)
commitd36c97612990ac81d2dc0452b980e8708477df76 (patch)
treef3c9948efc6a27a8aab8c14a68073eb70f7327fb /plugins/t/negate.t
parentc459ca07706ee315da3eac91344c2f1d9a152685 (diff)
downloadmonitoring-plugins-d36c97612990ac81d2dc0452b980e8708477df76.tar.gz
negate: make timeouts configurable
Diffstat (limited to 'plugins/t/negate.t')
-rw-r--r--plugins/t/negate.t31
1 files changed, 25 insertions, 6 deletions
diff --git a/plugins/t/negate.t b/plugins/t/negate.t
index 989bf01..0afe3ae 100644
--- a/plugins/t/negate.t
+++ b/plugins/t/negate.t
@@ -8,8 +8,8 @@ use strict;
8use Test::More; 8use Test::More;
9use NPTest; 9use NPTest;
10 10
11# 15 tests in the first part and 32 in the last loop 11# 15 tests in the first part, 9 in timeout tests and 2 * 32 in the last loops
12plan tests => 47; 12plan tests => 88;
13 13
14my $res; 14my $res;
15 15
@@ -53,18 +53,37 @@ is( $res->output, "No data returned from command", "Bad command, as expected (tr
53$res = NPTest->testCmd( './negate $PWD/check_dummy 0 \'$$ a dummy okay\'' ); 53$res = NPTest->testCmd( './negate $PWD/check_dummy 0 \'$$ a dummy okay\'' );
54is( $res->output, 'OK: $$ a dummy okay', 'Proves that $$ is not being expanded again' ); 54is( $res->output, 'OK: $$ a dummy okay', 'Proves that $$ is not being expanded again' );
55 55
56
57my %state = ( 56my %state = (
58 ok => 0, 57 ok => 0,
59 warning => 1, 58 warning => 1,
60 critical => 2, 59 critical => 2,
61 unknown => 3, 60 unknown => 3,
62 ); 61 );
63foreach my $current_state (qw(ok warning critical unknown)) { 62
64 foreach my $new_state (qw(ok warning critical unknown)) { 63# Timeout tests
64$res = NPTest->testCmd( "./negate -t 2 /bin/sh -c 'sleep 5'" );
65is( $res->output, 'CRITICAL - Plugin timed out after 2 seconds' );
66
67foreach my $state (keys(%state)) {
68 $res = NPTest->testCmd( "./negate -t 2 -T $state /bin/sh -c 'sleep 5'" );
69 is( $res->return_code, $state{$state}, "Got timeout state $state" );
70 is( $res->output, uc($state)." - Plugin timed out after 2 seconds", "Timeout state $state output");
71}
72
73foreach my $current_state (keys(%state)) {
74 foreach my $new_state (keys(%state)) {
65 $res = NPTest->testCmd( "./negate --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" ); 75 $res = NPTest->testCmd( "./negate --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" );
66 is( $res->return_code, $state{$new_state}, "Got fake $new_state" ); 76 is( $res->return_code, $state{$new_state}, "Got fake $new_state" );
67 is( $res->output, uc($current_state).": Fake $new_state" ); 77 is( $res->output, uc($current_state).": Fake $new_state", "Fake $new_state output");
78 }
79}
80
81# Same as aboce with substitute
82foreach my $current_state (keys(%state)) {
83 foreach my $new_state (keys(%state)) {
84 $res = NPTest->testCmd( "./negate -s --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" );
85 is( $res->return_code, $state{$new_state}, "Got fake $new_state (with substitute)" );
86 is( $res->output, uc($new_state).": Fake $new_state", "Substitued fake $new_state output");
68 } 87 }
69} 88}
70 89