net-dns 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/AUTHORS.rdoc +7 -0
- data/CHANGELOG.rdoc +34 -0
- data/README.rdoc +26 -14
- data/Rakefile +23 -30
- data/{THANKS → THANKS.rdoc} +0 -0
- data/VERSION.yml +3 -2
- data/demo/check_soa.rb +6 -11
- data/lib/net/{dns/dns.rb → dns.rb} +5 -12
- data/lib/net/dns/core_ext.rb +52 -0
- data/lib/net/dns/header.rb +55 -49
- data/lib/net/dns/names/names.rb +20 -10
- data/lib/net/dns/packet.rb +33 -26
- data/lib/net/dns/question.rb +60 -27
- data/lib/net/dns/resolver.rb +101 -156
- data/lib/net/dns/resolver/timeouts.rb +71 -65
- data/lib/net/dns/rr.rb +131 -166
- data/lib/net/dns/rr/a.rb +20 -26
- data/lib/net/dns/rr/aaaa.rb +15 -20
- data/lib/net/dns/rr/classes.rb +1 -1
- data/lib/net/dns/rr/cname.rb +8 -14
- data/lib/net/dns/rr/hinfo.rb +8 -14
- data/lib/net/dns/rr/mr.rb +8 -14
- data/lib/net/dns/rr/mx.rb +11 -18
- data/lib/net/dns/rr/ns.rb +8 -14
- data/lib/net/dns/rr/null.rb +7 -14
- data/lib/net/dns/rr/ptr.rb +9 -15
- data/lib/net/dns/rr/soa.rb +9 -15
- data/lib/net/dns/rr/srv.rb +10 -19
- data/lib/net/dns/rr/txt.rb +9 -20
- data/lib/net/dns/rr/types.rb +51 -58
- data/lib/net/dns/version.rb +22 -0
- data/test/{net/dns/test_header.rb → header_test.rb} +20 -20
- data/test/{net/dns/test_packet.rb → packet_test.rb} +2 -2
- data/test/question_test.rb +84 -0
- data/test/resolver/timeouts_test.rb +109 -0
- data/test/{net/dns/test_resolver.rb → resolver_test.rb} +6 -6
- data/test/rr/a_test.rb +66 -0
- data/test/{net/dns/rr/test_classes.rb → rr/classes_test.rb} +5 -5
- data/test/rr/ns_test.rb +64 -0
- data/test/rr/types_test.rb +69 -0
- data/test/{net/dns/test_rr.rb → rr_test.rb} +10 -12
- data/test/test_helper.rb +4 -0
- metadata +50 -35
- data/AUTHORS +0 -10
- data/CHANGELOG +0 -7
- data/INSTALL +0 -8
- data/net-dns.gemspec +0 -92
- data/test/net/dns/resolver/test_timeouts.rb +0 -59
- data/test/net/dns/rr/test_a.rb +0 -72
- data/test/net/dns/rr/test_ns.rb +0 -66
- data/test/net/dns/rr/test_types.rb +0 -124
- data/test/net/dns/test_question.rb +0 -54
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'net/dns/question'
|
3
|
+
|
4
|
+
class QuestionTest < Test::Unit::TestCase
|
5
|
+
include Net::DNS
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@domain = 'example.com.'
|
9
|
+
@type = 'MX'
|
10
|
+
@cls = 'HS'
|
11
|
+
@data = "\006google\003com\000\000\001\000\001"
|
12
|
+
|
13
|
+
@default = Question.new(@domain)
|
14
|
+
@string = Question.new(@domain,@type,@cls)
|
15
|
+
@binary = Question.parse(@data)
|
16
|
+
@binary2 = Question.parse(@string.data)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_simple
|
20
|
+
assert_equal(@default.qName, @domain)
|
21
|
+
assert_equal(@default.qType.to_s, "A")
|
22
|
+
assert_equal(@default.qClass.to_s, "IN")
|
23
|
+
|
24
|
+
assert_equal(@string.qName, @domain)
|
25
|
+
assert_equal(@string.qType.to_s, "MX")
|
26
|
+
assert_equal(@string.qClass.to_s, "HS")
|
27
|
+
|
28
|
+
assert_equal(@binary.qName, "google.com.")
|
29
|
+
assert_equal(@binary.qType.to_s, "A")
|
30
|
+
assert_equal(@binary.qClass.to_s, "IN")
|
31
|
+
|
32
|
+
assert_equal(@binary2.qName, @domain)
|
33
|
+
assert_equal(@binary2.qType.to_s, "MX")
|
34
|
+
assert_equal(@binary2.qClass.to_s, "HS")
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_raise
|
38
|
+
assert_raise(Net::DNS::Question::NameError) do
|
39
|
+
Question.new(1)
|
40
|
+
end
|
41
|
+
assert_raise(Net::DNS::Question::NameError) do
|
42
|
+
Question.new("test{")
|
43
|
+
end
|
44
|
+
assert_raise(Net::DNS::Question::ArgumentError) do
|
45
|
+
Question.parse(Array.new)
|
46
|
+
end
|
47
|
+
assert_raise(Net::DNS::Question::ArgumentError) do
|
48
|
+
Question.parse("test")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_inspect
|
53
|
+
assert_equal "google.com. IN A ",
|
54
|
+
Net::DNS::Question.new("google.com.").inspect
|
55
|
+
assert_equal "google.com. IN A ",
|
56
|
+
Net::DNS::Question.new("google.com.", Net::DNS::A).inspect
|
57
|
+
assert_equal "google.com. IN NS ",
|
58
|
+
Net::DNS::Question.new("google.com.", Net::DNS::NS).inspect
|
59
|
+
assert_equal "google.com. IN NS ",
|
60
|
+
Net::DNS::Question.new("google.com.", Net::DNS::NS).inspect
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_inspect_with_name_longer_than_29_chrs
|
64
|
+
assert_equal "supercalifragilistichespiralidoso.com IN A ",
|
65
|
+
Net::DNS::Question.new("supercalifragilistichespiralidoso.com").inspect
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_to_s
|
69
|
+
assert_equal "google.com. IN A ",
|
70
|
+
Net::DNS::Question.new("google.com.").to_s
|
71
|
+
assert_equal "google.com. IN A ",
|
72
|
+
Net::DNS::Question.new("google.com.", Net::DNS::A).to_s
|
73
|
+
assert_equal "google.com. IN NS ",
|
74
|
+
Net::DNS::Question.new("google.com.", Net::DNS::NS).to_s
|
75
|
+
assert_equal "google.com. IN NS ",
|
76
|
+
Net::DNS::Question.new("google.com.", Net::DNS::NS).to_s
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_to_s_with_name_longer_than_29_chrs
|
80
|
+
assert_equal "supercalifragilistichespiralidoso.com IN A ",
|
81
|
+
Net::DNS::Question.new("supercalifragilistichespiralidoso.com").to_s
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'net/dns/resolver/timeouts'
|
3
|
+
|
4
|
+
class DnsTimeoutTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@klass = Net::DNS::Resolver::DnsTimeout
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_initialize
|
11
|
+
timeout = @klass.new(0)
|
12
|
+
assert_instance_of @klass, timeout
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_initialize_should_set_timeout
|
16
|
+
assert_equal 0, @klass.new(0).seconds
|
17
|
+
assert_equal 10, @klass.new(10).seconds
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_initialize_should_set_raise_with_invalid_timeout
|
21
|
+
assert_raise(ArgumentError) { @klass.new(nil) }
|
22
|
+
assert_raise(ArgumentError) { @klass.new("") }
|
23
|
+
assert_raise(ArgumentError) { @klass.new("foo") }
|
24
|
+
assert_raise(ArgumentError) { @klass.new(-1) }
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def test_to_s
|
29
|
+
assert_equal "", @klass.new(0).to_s
|
30
|
+
assert_equal "1", @klass.new(1).to_s
|
31
|
+
assert_equal "10", @klass.new(10).to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def test_timeout_should_raise_localjumperror_without_block
|
36
|
+
assert_raise(LocalJumpError) { @klass.new(1).timeout }
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
class TcpTimeoutTest < Test::Unit::TestCase
|
42
|
+
|
43
|
+
def test_initialize
|
44
|
+
assert_raise(ArgumentError) do
|
45
|
+
Net::DNS::Resolver::TcpTimeout.new("a")
|
46
|
+
end
|
47
|
+
assert_raise(ArgumentError) do
|
48
|
+
Net::DNS::Resolver::TcpTimeout.new(-1)
|
49
|
+
end
|
50
|
+
assert_raise(TimeoutError) do
|
51
|
+
Net::DNS::Resolver::TcpTimeout.new(0.1).timeout { sleep 2 }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_to_s
|
56
|
+
assert_equal "infinite", Net::DNS::Resolver::TcpTimeout.new(0).to_s
|
57
|
+
assert_equal "30", Net::DNS::Resolver::TcpTimeout.new(30).to_s
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_pretty_to_s
|
61
|
+
assert_equal "30 seconds", Net::DNS::Resolver::TcpTimeout.new(30).pretty_to_s
|
62
|
+
assert_equal "1 minutes and 30 seconds", Net::DNS::Resolver::TcpTimeout.new(90).pretty_to_s
|
63
|
+
assert_equal "1 hours, 1 minutes and 30 seconds", Net::DNS::Resolver::TcpTimeout.new(3690).pretty_to_s
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_timeout
|
67
|
+
assert_equal 2, Net::DNS::Resolver::TcpTimeout.new(1).timeout { 1 + 1 }
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_timeout_should_raise_localjumperror_without_block
|
71
|
+
assert_raise(LocalJumpError) { Net::DNS::Resolver::TcpTimeout.new(1).timeout }
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
class UdpTimeoutTest < Test::Unit::TestCase
|
77
|
+
|
78
|
+
def test_initialize
|
79
|
+
assert_raise(ArgumentError) do
|
80
|
+
Net::DNS::Resolver::UdpTimeout.new("a")
|
81
|
+
end
|
82
|
+
assert_raise(ArgumentError) do
|
83
|
+
Net::DNS::Resolver::UdpTimeout.new(-1)
|
84
|
+
end
|
85
|
+
assert_raise(TimeoutError) do
|
86
|
+
Net::DNS::Resolver::UdpTimeout.new(0.1).timeout {sleep 2}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_to_s
|
91
|
+
assert_equal "not defined", Net::DNS::Resolver::UdpTimeout.new(0).to_s
|
92
|
+
assert_equal "30", Net::DNS::Resolver::UdpTimeout.new(30).to_s
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_pretty_to_s
|
96
|
+
assert_equal "30 seconds", Net::DNS::Resolver::UdpTimeout.new(30).pretty_to_s
|
97
|
+
assert_equal "1 minutes and 30 seconds", Net::DNS::Resolver::UdpTimeout.new(90).pretty_to_s
|
98
|
+
assert_equal "1 hours, 1 minutes and 30 seconds", Net::DNS::Resolver::UdpTimeout.new(3690).pretty_to_s
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_timeout
|
102
|
+
assert_equal 2, Net::DNS::Resolver::UdpTimeout.new(1).timeout { 1 + 1 }
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_timeout_should_raise_localjumperror_without_block
|
106
|
+
assert_raise(LocalJumpError) { Net::DNS::Resolver::UdpTimeout.new(1).timeout }
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'net/dns/resolver'
|
3
3
|
|
4
4
|
class Net::DNS::Resolver
|
@@ -6,7 +6,7 @@ class Net::DNS::Resolver
|
|
6
6
|
end
|
7
7
|
|
8
8
|
|
9
|
-
class
|
9
|
+
class ResolverTest < Test::Unit::TestCase
|
10
10
|
|
11
11
|
def test_initialize
|
12
12
|
assert_nothing_raised { Net::DNS::Resolver.new }
|
@@ -16,10 +16,10 @@ class TestResolver < Test::Unit::TestCase
|
|
16
16
|
assert_nothing_raised { Net::DNS::Resolver.new({}) }
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
assert_raise(
|
21
|
-
assert_raise(
|
22
|
-
assert_raise(
|
19
|
+
def test_initialize_with_invalid_config_should_raise_argumenterror
|
20
|
+
assert_raise(Net::DNS::Resolver::ArgumentError) { Net::DNS::Resolver.new("") }
|
21
|
+
assert_raise(Net::DNS::Resolver::ArgumentError) { Net::DNS::Resolver.new(0) }
|
22
|
+
assert_raise(Net::DNS::Resolver::ArgumentError) { Net::DNS::Resolver.new(:foo) }
|
23
23
|
end
|
24
24
|
|
25
25
|
|
data/test/rr/a_test.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'net/dns/rr'
|
3
|
+
|
4
|
+
class RRATest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@rr_name = "google.com."
|
8
|
+
@rr_type = "A"
|
9
|
+
@rr_cls = "IN"
|
10
|
+
@rr_ttl = 10800
|
11
|
+
@rr_address = "64.233.187.99"
|
12
|
+
|
13
|
+
@rr_output = "google.com. 10800 IN A 64.233.187.99"
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def test_initialize_from_hash
|
18
|
+
@record = Net::DNS::RR::A.new(:name => @rr_name, :address => @rr_address)
|
19
|
+
assert_equal @rr_output, @record.inspect
|
20
|
+
assert_equal @rr_name, @record.name
|
21
|
+
assert_equal @rr_type, @record.type
|
22
|
+
assert_equal @rr_cls, @record.cls
|
23
|
+
assert_equal @rr_ttl, @record.ttl
|
24
|
+
assert_equal @rr_address, @record.address.to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_initialize_from_string
|
28
|
+
@record = Net::DNS::RR::A.new("#{@rr_name} 10800 IN A #{@rr_address}")
|
29
|
+
assert_equal @rr_output, @record.inspect
|
30
|
+
assert_equal @rr_name, @record.name
|
31
|
+
assert_equal @rr_type, @record.type
|
32
|
+
assert_equal @rr_cls, @record.cls
|
33
|
+
assert_equal @rr_ttl, @record.ttl
|
34
|
+
assert_equal @rr_address, @record.address.to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_parse
|
38
|
+
data = "\006google\003com\000\000\001\000\001\000\000*0\000\004@\351\273c"
|
39
|
+
@record = Net::DNS::RR.parse(data)
|
40
|
+
assert_equal @rr_output, @record.inspect
|
41
|
+
assert_equal @rr_name, @record.name
|
42
|
+
assert_equal @rr_type, @record.type
|
43
|
+
assert_equal @rr_cls, @record.cls
|
44
|
+
assert_equal @rr_ttl, @record.ttl
|
45
|
+
assert_equal @rr_address, @record.address.to_s
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
InvalidArguments = [
|
50
|
+
{ :name => "google.com", :address => "255.256" },
|
51
|
+
{ :name => "google.com" },
|
52
|
+
Object.new,
|
53
|
+
Array.new(7),
|
54
|
+
"10800 IN A",
|
55
|
+
"google.com. 10800 IN B",
|
56
|
+
"google.com. 10800 IM A",
|
57
|
+
]
|
58
|
+
|
59
|
+
InvalidArguments.each_with_index do |arguments, index|
|
60
|
+
define_method "test_initialize_should_raise_with_invalid_arguments_#{index}" do
|
61
|
+
assert_raise(Net::DNS::RR::ArgumentError) { Net::DNS::RR::A.new(arguments) }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
@@ -1,7 +1,8 @@
|
|
1
|
-
require '
|
2
|
-
require 'net/dns/rr
|
1
|
+
require 'test_helper'
|
2
|
+
require 'net/dns/rr'
|
3
3
|
|
4
|
-
class
|
4
|
+
class RRClassesTest < Test::Unit::TestCase
|
5
|
+
|
5
6
|
def setup
|
6
7
|
@classes = {
|
7
8
|
'IN' => 1, # RFC 1035
|
@@ -10,7 +11,7 @@ class Test_Classes < Test::Unit::TestCase
|
|
10
11
|
'NONE' => 254, # RFC 2136
|
11
12
|
'ANY' => 255, # RFC 1035
|
12
13
|
}
|
13
|
-
@regexp_string = "
|
14
|
+
@regexp_string = "ANY|CH|HS|IN|NONE"
|
14
15
|
end
|
15
16
|
|
16
17
|
def test_default
|
@@ -29,7 +30,6 @@ class Test_Classes < Test::Unit::TestCase
|
|
29
30
|
instance = Net::DNS::RR::Classes.new(nil)
|
30
31
|
assert_equal("1", instance.to_str)
|
31
32
|
assert_equal("IN", instance.to_s)
|
32
|
-
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_classes
|
data/test/rr/ns_test.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'net/dns/rr'
|
3
|
+
|
4
|
+
class RRNSTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@rr_name = "google.com."
|
8
|
+
@rr_type = "NS"
|
9
|
+
@rr_cls = "IN"
|
10
|
+
@rr_ttl = 10800
|
11
|
+
@rr_nsdname = "ns1.google.com."
|
12
|
+
|
13
|
+
@rr_output = "google.com. 10800 IN NS ns1.google.com."
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def test_initialize_from_hash
|
18
|
+
@record = Net::DNS::RR::NS.new(:name => @rr_name, :nsdname => @rr_nsdname)
|
19
|
+
assert_equal @rr_output, @record.inspect
|
20
|
+
assert_equal @rr_name, @record.name
|
21
|
+
assert_equal @rr_type, @record.type
|
22
|
+
assert_equal @rr_cls, @record.cls
|
23
|
+
assert_equal @rr_ttl, @record.ttl
|
24
|
+
assert_equal @rr_nsdname, @record.nsdname
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_initialize_from_string
|
28
|
+
@record = Net::DNS::RR::NS.new("#{@rr_name} 10800 IN NS #{@rr_nsdname}")
|
29
|
+
assert_equal @rr_output, @record.inspect
|
30
|
+
assert_equal @rr_name, @record.name
|
31
|
+
assert_equal @rr_type, @record.type
|
32
|
+
assert_equal @rr_cls, @record.cls
|
33
|
+
assert_equal @rr_ttl, @record.ttl
|
34
|
+
assert_equal @rr_nsdname, @record.nsdname
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_parse
|
38
|
+
data = "\006google\003com\000\000\002\000\001\000\000*0\000\020\003ns1\006google\003com\000"
|
39
|
+
@record = Net::DNS::RR.parse(data)
|
40
|
+
assert_equal @rr_output, @record.inspect
|
41
|
+
assert_equal @rr_name, @record.name
|
42
|
+
assert_equal @rr_type, @record.type
|
43
|
+
assert_equal @rr_cls, @record.cls
|
44
|
+
assert_equal @rr_ttl, @record.ttl
|
45
|
+
assert_equal @rr_nsdname, @record.nsdname
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
InvalidArguments = [
|
50
|
+
{ :name => "google.com", :address => "255.256" },
|
51
|
+
{ :name => "google.com" },
|
52
|
+
Object.new,
|
53
|
+
Array.new(7),
|
54
|
+
"10800 IN A",
|
55
|
+
]
|
56
|
+
|
57
|
+
InvalidArguments.each_with_index do |arguments, index|
|
58
|
+
define_method "test_initialize_should_raise_with_invalid_arguments_#{index}" do
|
59
|
+
assert_raise(Net::DNS::RR::ArgumentError) { Net::DNS::RR::A.new(arguments) }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'net/dns/rr'
|
3
|
+
|
4
|
+
class RRTypesTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_default
|
10
|
+
# Default type should be ANY => 255
|
11
|
+
instance = Net::DNS::RR::Types.new(nil)
|
12
|
+
assert_equal("1", instance.to_str)
|
13
|
+
assert_equal("A", instance.to_s)
|
14
|
+
|
15
|
+
# Let's change default behaviour
|
16
|
+
Net::DNS::RR::Types.default = "A"
|
17
|
+
instance = Net::DNS::RR::Types.new(nil)
|
18
|
+
assert_equal("1", instance.to_str)
|
19
|
+
assert_equal("A", instance.to_s)
|
20
|
+
|
21
|
+
Net::DNS::RR::Types.default = "ANY"
|
22
|
+
instance = Net::DNS::RR::Types.new(nil)
|
23
|
+
assert_equal("255", instance.to_str)
|
24
|
+
assert_equal("ANY", instance.to_s)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_types
|
28
|
+
Net::DNS::RR::Types::TYPES.each do |key, num|
|
29
|
+
instance_from_string = Net::DNS::RR::Types.new(key)
|
30
|
+
instance_from_num = Net::DNS::RR::Types.new(num)
|
31
|
+
assert_equal(key, instance_from_string.to_s)
|
32
|
+
assert_equal(num.to_s, instance_from_string.to_str)
|
33
|
+
assert_equal(key, instance_from_num.to_s)
|
34
|
+
assert_equal(num.to_s, instance_from_num.to_str)
|
35
|
+
end
|
36
|
+
assert_raise(Net::DNS::RR::ArgumentError) do
|
37
|
+
Net::DNS::RR::Types.new(Hash.new)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_regexp
|
42
|
+
pattern = Net::DNS::RR::Types.regexp
|
43
|
+
assert_instance_of String, pattern
|
44
|
+
Net::DNS::RR::Types::TYPES.each do |key, num|
|
45
|
+
assert_match /\|?#{key}\|?/, pattern
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_valid?
|
50
|
+
assert_equal(true, Net::DNS::RR::Types.valid?("A"))
|
51
|
+
assert_equal(true, Net::DNS::RR::Types.valid?(1))
|
52
|
+
assert_equal(false, Net::DNS::RR::Types.valid?("Q"))
|
53
|
+
assert_equal(false, Net::DNS::RR::Types.valid?(256))
|
54
|
+
assert_raise(Net::DNS::RR::ArgumentError) do
|
55
|
+
Net::DNS::RR::Types.valid? Hash.new
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_to_str
|
60
|
+
assert_equal("A", Net::DNS::RR::Types.to_str(1))
|
61
|
+
assert_raise(Net::DNS::RR::ArgumentError) do
|
62
|
+
Net::DNS::RR::Types.to_str(256)
|
63
|
+
end
|
64
|
+
assert_raise(Net::DNS::RR::ArgumentError) do
|
65
|
+
Net::DNS::RR::Types.to_str("string")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|