diff options
Diffstat (limited to 'plugins-root/t/check_dhcp.t')
-rw-r--r-- | plugins-root/t/check_dhcp.t | 55 |
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; | |||
8 | use NPTest; | 8 | use NPTest; |
9 | 9 | ||
10 | my $allow_sudo = getTestParameter( "NP_ALLOW_SUDO", | 10 | my $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 | ||
14 | if ($allow_sudo eq "yes" or $> == 0) { | 14 | if ($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 | } |
19 | my $sudo = $> == 0 ? '' : 'sudo'; | 19 | my $sudo = $> == 0 ? '' : 'sudo'; |
20 | 20 | ||
21 | my $successOutput = '/OK: Received \d+ DHCPOFFER\(s\), \d+ of 1 requested servers responded, max lease time = \d+ sec\./'; | 21 | my $successOutput = '/OK: Received \d+ DHCPOFFER\(s\), \d+ of 1 requested servers responded, max lease time = \d+ sec\./'; |
22 | my $failureOutput = '/CRITICAL: Received \d+ DHCPOFFER\(s\), 0 of \d+ requested servers responded/'; | 22 | my $failureOutput = '/CRITICAL: Received \d+ DHCPOFFER\(s\), 0 of \d+ requested servers responded/'; |
23 | my $invalidOutput = '/Invalid hostname/'; | ||
23 | 24 | ||
24 | my $host_responsive = getTestParameter( "NP_HOST_DHCP_RESPONSIVE", | 25 | my $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 | ||
28 | my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", | 29 | my $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 | ||
32 | my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID", | 33 | my $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 | ||
36 | my $res; | 37 | my $res; |
37 | 38 | ||
38 | $res = NPTest->testCmd( | 39 | SKIP: { |
39 | "$sudo ./check_dhcp -s $host_responsive" | 40 | skip('need responsive test host', 2) unless $host_responsive; |
40 | ); | 41 | $res = NPTest->testCmd( |
41 | is( $res->return_code, 0, "Syntax ok" ); | 42 | "$sudo ./check_dhcp -s $host_responsive" |
42 | like( $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( | 48 | SKIP: { |
45 | "$sudo ./check_dhcp -s $host_nonresponsive" | 49 | skip('need nonresponsive test host', 2) unless $host_nonresponsive; |
46 | ); | 50 | $res = NPTest->testCmd( |
47 | is( $res->return_code, 2, "Timeout - host nonresponsive" ); | 51 | "$sudo ./check_dhcp -s $host_nonresponsive" |
48 | like( $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 | ||
57 | SKIP: { | ||
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 | }; | ||