diff options
author | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2009-03-20 02:28:02 -0400 |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2009-03-20 02:28:02 -0400 |
commit | d36c97612990ac81d2dc0452b980e8708477df76 (patch) | |
tree | f3c9948efc6a27a8aab8c14a68073eb70f7327fb /plugins/t | |
parent | c459ca07706ee315da3eac91344c2f1d9a152685 (diff) | |
download | monitoring-plugins-d36c97612990ac81d2dc0452b980e8708477df76.tar.gz |
negate: make timeouts configurable
Diffstat (limited to 'plugins/t')
-rw-r--r-- | plugins/t/negate.t | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/plugins/t/negate.t b/plugins/t/negate.t index 989bf01f..0afe3ae6 100644 --- a/plugins/t/negate.t +++ b/plugins/t/negate.t | |||
@@ -8,8 +8,8 @@ use strict; | |||
8 | use Test::More; | 8 | use Test::More; |
9 | use NPTest; | 9 | use 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 |
12 | plan tests => 47; | 12 | plan tests => 88; |
13 | 13 | ||
14 | my $res; | 14 | my $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\'' ); |
54 | is( $res->output, 'OK: $$ a dummy okay', 'Proves that $$ is not being expanded again' ); | 54 | is( $res->output, 'OK: $$ a dummy okay', 'Proves that $$ is not being expanded again' ); |
55 | 55 | ||
56 | |||
57 | my %state = ( | 56 | my %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 | ); |
63 | foreach 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'" ); | ||
65 | is( $res->output, 'CRITICAL - Plugin timed out after 2 seconds' ); | ||
66 | |||
67 | foreach 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 | |||
73 | foreach 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 | ||
82 | foreach 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 | ||