From 9e677261a9147616c32bb32004fcf99e868563d7 Mon Sep 17 00:00:00 2001 From: naruse Date: Thu, 11 Jan 2018 18:26:49 +0000 Subject: [PATCH] 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 --- lib/resolv.rb | 2 +- test/resolv/test_mdns.rb | 28 ++++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/resolv.rb b/lib/resolv.rb index 48ee400efe..d38204eeca 100644 --- a/lib/resolv.rb +++ b/lib/resolv.rb @@ -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 diff --git a/test/resolv/test_mdns.rb b/test/resolv/test_mdns.rb index 8e401883f1..9c17f9b219 100644 --- a/test/resolv/test_mdns.rb +++ b/test/resolv/test_mdns.rb @@ -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