summaryrefslogtreecommitdiffstats
path: root/plugins-root/t/check_dhcp.t
diff options
context:
space:
mode:
authorSven Nierlein <sven@nierlein.de>2013-09-16 08:51:04 +0200
committerSven Nierlein <sven@nierlein.de>2013-09-16 08:51:04 +0200
commit095e2e5db52ff5ff60eb319099d047c7c060d800 (patch)
tree1d1501b471c7eae230fea64a545cda329c9ebfa4 /plugins-root/t/check_dhcp.t
parent5d58592cfe75baae10c4722f4fa6c17ca1256d1e (diff)
downloadmonitoring-plugins-095e2e5db52ff5ff60eb319099d047c7c060d800.tar.gz
check_dhcp test: skip subtests if no variable is set
Diffstat (limited to 'plugins-root/t/check_dhcp.t')
-rw-r--r--plugins-root/t/check_dhcp.t55
1 files changed, 35 insertions, 20 deletions
diff --git a/plugins-root/t/check_dhcp.t b/plugins-root/t/check_dhcp.t
index 1f7c518c..a7ce1e20 100644
--- a/plugins-root/t/check_dhcp.t
+++ b/plugins-root/t/check_dhcp.t
@@ -8,42 +8,57 @@ use Test::More;
8use NPTest; 8use NPTest;
9 9
10my $allow_sudo = getTestParameter( "NP_ALLOW_SUDO", 10my $allow_sudo = getTestParameter( "NP_ALLOW_SUDO",
11 "If sudo is setup for this user to run any command as root ('yes' to allow)", 11 "If sudo is setup for this user to run any command as root ('yes' to allow)",
12 "no" ); 12 "no" );
13 13
14if ($allow_sudo eq "yes" or $> == 0) { 14if ($allow_sudo eq "yes" or $> == 0) {
15 plan tests => 4; 15 plan tests => 6;
16} else { 16} else {
17 plan skip_all => "Need sudo to test check_dhcp"; 17 plan skip_all => "Need sudo to test check_dhcp";
18} 18}
19my $sudo = $> == 0 ? '' : 'sudo'; 19my $sudo = $> == 0 ? '' : 'sudo';
20 20
21my $successOutput = '/OK: Received \d+ DHCPOFFER\(s\), \d+ of 1 requested servers responded, max lease time = \d+ sec\./'; 21my $successOutput = '/OK: Received \d+ DHCPOFFER\(s\), \d+ of 1 requested servers responded, max lease time = \d+ sec\./';
22my $failureOutput = '/CRITICAL: Received \d+ DHCPOFFER\(s\), 0 of \d+ requested servers responded/'; 22my $failureOutput = '/CRITICAL: Received \d+ DHCPOFFER\(s\), 0 of \d+ requested servers responded/';
23my $invalidOutput = '/Invalid hostname/';
23 24
24my $host_responsive = getTestParameter( "NP_HOST_DHCP_RESPONSIVE", 25my $host_responsive = getTestParameter( "NP_HOST_DHCP_RESPONSIVE",
25 "The hostname of system responsive to dhcp requests", 26 "The hostname of system responsive to dhcp requests",
26 "localhost" ); 27 "localhost" );
27 28
28my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", 29my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
29 "The hostname of system not responsive to dhcp requests", 30 "The hostname of system not responsive to dhcp requests",
30 "10.0.0.1" ); 31 "10.0.0.1" );
31 32
32my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID", 33my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
33 "An invalid (not known to DNS) hostname", 34 "An invalid (not known to DNS) hostname",
34 "nosuchhost" ); 35 "nosuchhost" );
35 36
36my $res; 37my $res;
37 38
38$res = NPTest->testCmd( 39SKIP: {
39 "$sudo ./check_dhcp -s $host_responsive" 40 skip('need responsive test host', 2) unless $host_responsive;
40 ); 41 $res = NPTest->testCmd(
41is( $res->return_code, 0, "Syntax ok" ); 42 "$sudo ./check_dhcp -s $host_responsive"
42like( $res->output, $successOutput, "Output OK" ); 43 );
44 is( $res->return_code, 0, "Syntax ok" );
45 like( $res->output, $successOutput, "Output OK" );
46};
43 47
44$res = NPTest->testCmd( 48SKIP: {
45 "$sudo ./check_dhcp -s $host_nonresponsive" 49 skip('need nonresponsive test host', 2) unless $host_nonresponsive;
46 ); 50 $res = NPTest->testCmd(
47is( $res->return_code, 2, "Timeout - host nonresponsive" ); 51 "$sudo ./check_dhcp -s $host_nonresponsive"
48like( $res->output, $failureOutput, "Output OK" ); 52 );
53 is( $res->return_code, 2, "Exit code - host nonresponsive" );
54 like( $res->output, $failureOutput, "Output OK" );
55};
49 56
57SKIP: {
58 skip('need invalid test host', 2) unless $hostname_invalid;
59 $res = NPTest->testCmd(
60 "$sudo ./check_dhcp -s $hostname_invalid"
61 );
62 is( $res->return_code, 3, "Exit code - host invalid" );
63 like( $res->output, $invalidOutput, "Output OK" );
64};