Sha256: 528f0b803d2159526609e327a311a829e13447f8f5a6a8e597615fa8db6af290

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

require 'helper'
require 'pathname'

require 'rubydns'
require 'rubydns/resolver'
require 'rubydns/extensions/string'

class TruncatedServer < RExec::Daemon::Base
	SERVER_PORTS = [[:udp, '127.0.0.1', 5320], [:tcp, '127.0.0.1', 5320]]
	
	@@base_directory = File.dirname(__FILE__)

	Name = Resolv::DNS::Name
	IN = Resolv::DNS::Resource::IN

	def self.run
		# Start the RubyDNS server
		RubyDNS::run_server(:listen => SERVER_PORTS) do
			match("truncation", IN::TXT) do |transaction|
				text = "Hello World! " * 100
				transaction.respond!(*text.chunked)
			end
			
			# Default DNS handler
			otherwise do |transaction|
				transaction.failure!(:NXDomain)
			end
		end
	end
end

class TruncationTest < Test::Unit::TestCase
	def setup
		TruncatedServer.start
	end
	
	def teardown
		TruncatedServer.stop
	end
	
	def test_tcp_failover
		resolver = RubyDNS::Resolver.new(TruncatedServer::SERVER_PORTS)
		
		EventMachine::run do
			resolver.query("truncation", IN::TXT) do |response|
				
				
				text = response.answer.first
				
				assert_equal "Hello World! " * 100, text[2].strings.join
				
				EventMachine::stop
			end
		end
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubydns-0.5.2 test/test_truncation.rb
rubydns-0.5.1 test/test_truncation.rb