summaryrefslogtreecommitdiff
path: root/t/test-custodian-util-dns.rb
blob: c86f9373055db03564d9daa966c52694504260ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/ruby -I./lib/ -I../lib/


require 'custodian/util/dns'
require 'test/unit'
require 'pp'


#
# 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

    details = Custodian::Util::DNS.hostname_to_ip('bytemark.co.uk')
    assert((details == '2001:41c9:0:1019:81::80') ||
            (details == '80.68.81.80'))

    details = Custodian::Util::DNS.hostname_to_ip('www.bytemark.co.uk')
    assert((details == '2001:41c9:0:1019:81::80') ||
            (details == '80.68.81.80'))


    details = Custodian::Util::DNS.hostname_to_ip('ipv4.steve.org.uk')
    assert(details == '80.68.84.111')

    details = Custodian::Util::DNS.hostname_to_ip('ipv6.steve.org.uk')
    assert(details == '2001:41c8:10b:103::111')


    #
    # 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:41c9:0:1019:81::80')
    assert(details =~ /bytemark(-?hosting)?\.(com|eu|co\.uk)$/i)

    #
    # IPv4 lookup
    #
    details = Custodian::Util::DNS.ip_to_hostname('80.68.81.80')
    assert(details =~ /bytemark(-?hosting)?\.(com|eu|co\.uk)$/i)

    #
    # Bogus lookup - should return nil.
    #
    details = Custodian::Util::DNS.ip_to_hostname('800.683.853.348')
    assert(details.nil?)
  end

end