ruby-changes:49658
From: naruse <ko1@a...>
Date: Fri, 12 Jan 2018 03:26:55 +0900 (JST)
Subject: [ruby-changes:49658] naruse:r61774 (trunk): Mock fetching data from real DNS [Feature #14340]
naruse 2018-01-12 03:26:49 +0900 (Fri, 12 Jan 2018) New Revision: 61774 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61774 Log: Mock fetching data from real DNS [Feature #14340] This test just tests MDNS#each_address method. Modified files: trunk/lib/resolv.rb trunk/test/resolv/test_mdns.rb Index: lib/resolv.rb =================================================================== --- lib/resolv.rb (revision 61773) +++ lib/resolv.rb (revision 61774) @@ -2603,7 +2603,7 @@ class Resolv https://github.com/ruby/ruby/blob/trunk/lib/resolv.rb#L2603 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 Index: test/resolv/test_mdns.rb =================================================================== --- test/resolv/test_mdns.rb (revision 61773) +++ test/resolv/test_mdns.rb (revision 61774) @@ -3,20 +3,24 @@ require 'test/unit' https://github.com/ruby/ruby/blob/trunk/test/resolv/test_mdns.rb#L3 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 + 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 - rescue Errno::EADDRNOTAVAIL - # Handle Raspberry Pi environment. + assert_equal expect, results, "GH-1484" end end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/