test/test_daemon.rb in rubydns-0.8.1 vs test/test_daemon.rb in rubydns-0.8.4

- old
+ new

@@ -27,14 +27,16 @@ require 'process/daemon' class BasicTestServer < Process::Daemon SERVER_PORTS = [[:udp, '127.0.0.1', 5350], [:tcp, '127.0.0.1', 5350]] - @@base_directory = File.dirname(__FILE__) - IN = Resolv::DNS::Resource::IN + def working_directory + File.expand_path("../tmp", __FILE__) + end + def startup # Start the RubyDNS server RubyDNS::run_server(:listen => SERVER_PORTS) do match("test.local", IN::A) do |transaction| transaction.respond!("192.168.1.1") @@ -42,10 +44,14 @@ match(/foo.*/, IN::A) do |transaction| transaction.respond!("192.168.1.2") end + match(/peername/, IN::A) do |transaction| + transaction.respond!(transaction[:connection].peername[1]) + end + # Default DNS handler otherwise do |transaction| transaction.fail!(:NXDomain) end end @@ -89,9 +95,25 @@ resolver.query("foobar") do |response| answer = response.answer.first assert_equal "foobar", answer[0].to_s assert_equal "192.168.1.2", answer[2].address.to_s + + EventMachine.stop + end + end + end + + def test_peername + assert_equal :running, BasicTestServer.status + + EventMachine.run do + resolver = RubyDNS::Resolver.new(BasicTestServer::SERVER_PORTS) + + resolver.query("peername") do |response| + answer = response.answer.first + + assert_equal "127.0.0.1", answer[2].address.to_s EventMachine.stop end end end