summaryrefslogtreecommitdiff
path: root/t/test-dns-types.rb
blob: e8da275e0d2365545e3306257edf286b1c2a527d (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
83
#!/usr/bin/ruby -Ilib/ -I../lib/


require 'test/unit'
require 'rubygems'
#require 'mocha/setup'
require 'mocha'
require 'custodian/protocoltests'



#
# The DNS test is a complex one.
#
class TestDNSTypes < Test::Unit::TestCase

  #
  # Create the test suite environment: NOP.
  #
  def setup
  end

  #
  # Destroy the test suite environment: NOP.
  #
  def teardown
  end


  #
  # Test the known-record types: A, NS, MX, AAAA
  #
  def test_known_types

    assert_nothing_raised do
     test = Custodian::TestFactory.create( "a.ns.bytemark.co.uk must run dns for bytemark.co.uk resolving NS as 'foo'." )
     test = Custodian::TestFactory.create( "a.ns.bytemark.co.uk must run dns for bytemark.co.uk resolving A as 'foo'." )
     test = Custodian::TestFactory.create( "a.ns.bytemark.co.uk must run dns for bytemark.co.uk resolving MX as 'foo'." )
     test = Custodian::TestFactory.create( "a.ns.bytemark.co.uk must run dns for bytemark.co.uk resolving AAAA as 'foo'." )
    end

  end



  #
  # Test that using random types fails.
  #
  def test_unknown_types

    #
    #  Each of these will fail
    #
    %w( a ns www example fdskfjdlfsj `` ).each do |res|
      assert_raise ArgumentError do
        Custodian::TestFactory.create( "a.ns.bytemark.co.uk must run dns for bytemark.co.uk resolving #{res} as 'foo'." )
      end
    end
  end

  #
  # Now test the protocol stuff, without doing the resolution itself.
  #
  def test_dns_protocol_test
     test = Custodian::TestFactory.create( "a.ns.bytemark.co.uk must run dns for bytemark.co.uk resolving A as '1.2.3.4,2001:lower::case,2001:UPPER::CASE'." )
     test.stubs(:resolve_via).returns(%w(2001:lower::case 2001:upper::case 1.2.3.4))
     assert test.run_test, "The error was #{test.error}"
    
     # Re-stub to return just one record 
     test.stubs(:resolve_via).returns(%w(1.2.3.4))
     assert !test.run_test
     
     # Re-stub to return too many records
     test.stubs(:resolve_via).returns(%w(2001:lower::case 2001:upper::case 1.2.3.4 1.2.3.5))
     assert !test.run_test

     # Re-stub to return no records
     test.stubs(:resolve_via).returns([])
     assert !test.run_test
  end

end