1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Mock fetching data from real DNS [Feature #14340]

This test just tests MDNS#each_address method.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61774 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2018-01-11 18:26:49 +00:00
parent ddb7996372
commit 9e677261a9
2 changed files with 17 additions and 13 deletions

View file

@ -2603,7 +2603,7 @@ class Resolv
def each_address(name)
name = Resolv::DNS::Name.create(name)
return unless name.to_a.last.to_s == 'local'
return unless name[-1].to_s == 'local'
super(name)
end

View file

@ -3,20 +3,24 @@ require 'test/unit'
require 'resolv'
class TestResolvMDNS < Test::Unit::TestCase
def setup
end
def test_mdns_each_address
begin
mdns = Resolv::MDNS.new
mdns.each_resource '_http._tcp.local', Resolv::DNS::Resource::IN::PTR do |r|
srv = mdns.getresource r.name, Resolv::DNS::Resource::IN::SRV
mdns.each_address(srv.target) do |result|
assert_not_nil(result)
end
mdns = Resolv::MDNS.new
def mdns.each_resource(name, typeclass)
if typeclass == Resolv::DNS::Resource::IN::A
yield typeclass.new("127.0.0.1")
else
yield typeclass.new("::1")
end
rescue Errno::EADDRNOTAVAIL
# Handle Raspberry Pi environment.
end
[
["example.com", []],
["foo.local", ["127.0.0.1"]],
].each do |name, expect|
results = []
mdns.each_address(name) do |result|
results << result.to_s
end
assert_equal expect, results, "GH-1484"
end
end
end