diff options
Diffstat (limited to 'plugins/t/check_dns.t')
| -rw-r--r-- | plugins/t/check_dns.t | 75 |
1 files changed, 53 insertions, 22 deletions
diff --git a/plugins/t/check_dns.t b/plugins/t/check_dns.t index fbaca794..5d750d3f 100644 --- a/plugins/t/check_dns.t +++ b/plugins/t/check_dns.t | |||
| @@ -6,37 +6,68 @@ | |||
| 6 | # | 6 | # |
| 7 | 7 | ||
| 8 | use strict; | 8 | use strict; |
| 9 | use Test; | 9 | use Test::More; |
| 10 | use NPTest; | 10 | use NPTest; |
| 11 | 11 | ||
| 12 | use vars qw($tests); | 12 | plan skip_all => "check_dns not compiled" unless (-x "check_dns"); |
| 13 | BEGIN {$tests = 6; plan tests => $tests} | 13 | |
| 14 | plan tests => 11; | ||
| 14 | 15 | ||
| 15 | my $successOutput = '/DNS OK: [\.0-9]+ seconds response time/'; | 16 | my $successOutput = '/DNS OK: [\.0-9]+ seconds response time/'; |
| 16 | 17 | ||
| 17 | my $hostname_valid = getTestParameter( "hostname_valid", "NP_HOSTNAME_VALID", "localhost", | 18 | my $hostname_valid = getTestParameter( |
| 18 | "A valid (known to DNS) hostname" ); | 19 | "NP_HOSTNAME_VALID", |
| 20 | "A valid (known to DNS) hostname", | ||
| 21 | "www.apple.com" | ||
| 22 | ); | ||
| 19 | 23 | ||
| 20 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | 24 | my $hostname_valid_ip = getTestParameter( |
| 21 | "An invalid (not known to DNS) hostname" ); | 25 | "NP_HOSTNAME_VALID_IP", |
| 26 | "The IP address of the valid hostname $hostname_valid", | ||
| 27 | "17.112.152.32" | ||
| 28 | ); | ||
| 22 | 29 | ||
| 23 | my $dns_server = getTestParameter( "dns_server", "NP_DNS_SERVER", undef, | 30 | my $hostname_valid_reverse = getTestParameter( |
| 24 | "A non default (remote) DNS server" ); | 31 | "NP_HOSTNAME_VALID_REVERSE", |
| 32 | "The hostname of $hostname_valid_ip", | ||
| 33 | $hostname_valid | ||
| 34 | ); | ||
| 25 | 35 | ||
| 26 | my $t; | 36 | my $hostname_invalid = getTestParameter( |
| 37 | "NP_HOSTNAME_INVALID", | ||
| 38 | "An invalid (not known to DNS) hostname", | ||
| 39 | "nosuchhost.altinity.com", | ||
| 40 | ); | ||
| 27 | 41 | ||
| 28 | # | 42 | my $dns_server = getTestParameter( |
| 29 | # Default DNS Server | 43 | "NP_DNS_SERVER", |
| 30 | # | 44 | "A non default (remote) DNS server", |
| 31 | $t += checkCmd( "./check_dns -H $hostname_valid -t 5", 0, $successOutput ); | 45 | ); |
| 32 | $t += checkCmd( "./check_dns -H $hostname_invalid -t 1", 2 ); | ||
| 33 | 46 | ||
| 34 | # | 47 | my $res; |
| 35 | # Specified DNS Server | 48 | |
| 36 | # | 49 | $res = NPTest->testCmd("./check_dns -H $hostname_valid -t 5"); |
| 37 | $t += checkCmd( "./check_dns -H $hostname_valid -s $dns_server -t 5", 0, $successOutput ); | 50 | cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid"); |
| 38 | $t += checkCmd( "./check_dns -H $hostname_invalid -s $dns_server -t 1", 2 ); | 51 | like ( $res->output, $successOutput, "Output OK" ); |
| 52 | |||
| 53 | $res = NPTest->testCmd("./check_dns -H $hostname_invalid -t 1"); | ||
| 54 | cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid"); | ||
| 55 | |||
| 56 | $res = NPTest->testCmd("./check_dns -H $hostname_valid -s $dns_server -t 5"); | ||
| 57 | cmp_ok( $res->return_code, '==', 0, "Found $hostname_valid on $dns_server"); | ||
| 58 | like ( $res->output, $successOutput, "Output OK" ); | ||
| 59 | |||
| 60 | $res = NPTest->testCmd("./check_dns -H $hostname_invalid -s $dns_server -t 1"); | ||
| 61 | cmp_ok( $res->return_code, '==', 2, "Invalid $hostname_invalid on $dns_server"); | ||
| 62 | |||
| 63 | $res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_ip -t 5"); | ||
| 64 | cmp_ok( $res->return_code, '==', 0, "Got expected address"); | ||
| 65 | |||
| 66 | $res = NPTest->testCmd("./check_dns -H $hostname_valid -a 10.10.10.10 -t 5"); | ||
| 67 | cmp_ok( $res->return_code, '==', 2, "Got wrong address"); | ||
| 68 | like ( $res->output, "/^DNS CRITICAL.*expected '10.10.10.10' but got '$hostname_valid_ip'".'$/', "Output OK"); | ||
| 39 | 69 | ||
| 40 | exit(0) if defined($Test::Harness::VERSION); | 70 | $res = NPTest->testCmd("./check_dns -H $hostname_valid_ip -a $hostname_valid_reverse -t 5"); |
| 41 | exit($tests - $t); | 71 | cmp_ok( $res->return_code, '==', 0, "Got expected fqdn"); |
| 72 | like ( $res->output, $successOutput, "Output OK"); | ||
| 42 | 73 | ||
