#!/usr/bin/ruby1.8 -I./lib/ -I../lib/ require 'custodian/util/dns' require 'test/unit' # # Unit test for our DNS utility class. # # class TestDNSUtil < 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 = Custodian::Util::DNS.hostname_to_ip( "bytemark.co.uk" ) assert( details == "212.110.161.236" ) # # IPv4 lookup # details = Custodian::Util::DNS.hostname_to_ip( "www.bytemark.co.uk" ) assert( details == "212.110.161.236" ) # # Failure case # details = Custodian::Util::DNS.hostname_to_ip( "this.doesnot.exist" ) assert( details.nil? ) end # # Test forward lookups # def test_reverse_lookup # # IPv6 lookup # details = Custodian::Util::DNS.ip_to_hostname( "2001:41c8:2::5" ) assert( details =~ /bytemark.co.uk/i ) # # IPv4 lookup # details = Custodian::Util::DNS.ip_to_hostname( "212.110.161.236" ) assert( details =~ /bytemark.co.uk/i ) # # Bogus lookup - should return nil. # details = Custodian::Util::DNS.ip_to_hostname( "800.683.853.348" ) assert( details.nil? ) end end