summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2012-11-20 10:32:10 +0000
committerSteve Kemp <steve@steve.org.uk>2012-11-20 10:32:10 +0000
commit8c6cc573323241f0a2524fccf5cbd9fd03a544a1 (patch)
tree7f9bd62fc5af4e96cd40308e1ece123f3500228a
parentca4d4abfd2ed4cffb31db76dcbef0cf128e7675e (diff)
New test cases for DNS lookup - basic.
-rwxr-xr-xt/test-dnsutil.rb79
1 files changed, 79 insertions, 0 deletions
diff --git a/t/test-dnsutil.rb b/t/test-dnsutil.rb
new file mode 100755
index 0000000..48f8658
--- /dev/null
+++ b/t/test-dnsutil.rb
@@ -0,0 +1,79 @@
+#!/usr/bin/ruby1.8 -I./lib/ -I../lib/
+
+
+
+require 'test/unit'
+require 'custodian/dnsutil'
+
+
+
+#
+# Unit test for our DNS utility class.
+#
+#
+class TestAlerter < Test::Unit::TestCase
+
+ #
+ # Create the test suite environment: NOP.
+ #
+ def setup
+ end
+
+ #
+ # Destroy the test suite environment: NOP.
+ #
+ def teardown
+ end
+
+
+ #
+ # Test forward lookups
+ #
+ def test_lookup
+
+ #
+ # IPv6 lookup
+ #
+ details = DNSUtil.hostname_to_ip( "ipv6.steve.org.uk" )
+ assert( details =~ /2001:41c8:125:46::10/i )
+
+ #
+ # IPv4 lookup
+ #
+ details = DNSUtil.hostname_to_ip( "ipv4.steve.org.uk" )
+ assert( details =~ /80.68.85.46/i )
+
+ #
+ # Failure case
+ #
+ details = DNSUtil.hostname_to_ip( "this.doesnot.exist" )
+ assert( details.nil? )
+
+ end
+
+
+ #
+ # Test forward lookups
+ #
+ def test_reverse_lookup
+
+ #
+ # IPv6 lookup
+ #
+ details = DNSUtil.ip_to_hostname( "2001:41c8:125:46::22" )
+ assert( details =~ /ssh.steve.org.uk/i )
+
+ #
+ # IPv4 lookup
+ #
+ details = DNSUtil.ip_to_hostname( "80.68.85.48" )
+ assert( details =~ /ssh.steve.org.uk/i )
+
+ #
+ # Bogus lookup - should return nil.
+ #
+ details = DNSUtil.ip_to_hostname( "800.683.853.348" )
+ assert( details.nil? )
+
+ end
+end