2017-10-21 09:58:31 -04:00
|
|
|
# frozen_string_literal: false
|
|
|
|
require 'test/unit'
|
|
|
|
require 'resolv'
|
|
|
|
|
|
|
|
class TestResolvMDNS < Test::Unit::TestCase
|
|
|
|
def test_mdns_each_address
|
2018-01-11 13:26:49 -05:00
|
|
|
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
|
2018-01-11 14:41:49 -05:00
|
|
|
addrs = mdns.__send__(:use_ipv6?) ? ["127.0.0.1", "::1"] : ["127.0.0.1"]
|
2018-01-11 13:26:49 -05:00
|
|
|
[
|
|
|
|
["example.com", []],
|
2018-01-11 14:41:49 -05:00
|
|
|
["foo.local", addrs],
|
2018-01-11 13:26:49 -05:00
|
|
|
].each do |name, expect|
|
|
|
|
results = []
|
|
|
|
mdns.each_address(name) do |result|
|
|
|
|
results << result.to_s
|
2017-10-21 09:58:31 -04:00
|
|
|
end
|
2018-01-11 14:41:49 -05:00
|
|
|
assert_equal expect, results.sort, "GH-1484"
|
2017-10-21 09:58:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|