From 1ffa21d62aee850f115deeeb770d19d16c6e663f Mon Sep 17 00:00:00 2001 From: soh_cah_toa Date: Mon, 15 Jul 2013 02:47:37 -0400 Subject: [PATCH] Added unit tests for #add_rule. These represent the first actual tests for the Dns::Server class. --- test/unit/extensions/tc_dns.rb | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/unit/extensions/tc_dns.rb b/test/unit/extensions/tc_dns.rb index 17a4d4c47..a4a75a4e3 100644 --- a/test/unit/extensions/tc_dns.rb +++ b/test/unit/extensions/tc_dns.rb @@ -31,6 +31,7 @@ class TC_Dns < Test::Unit::TestCase end + # Connects to in-memory database (does not test anything) def test_1_database DataMapper.setup(:default, 'sqlite3::memory:') DataMapper.auto_migrate! @@ -53,4 +54,42 @@ class TC_Dns < Test::Unit::TestCase assert(@@dns.respond_to?('get_rule')) end + # Starts DNS server (does not test anything) + def test_4_run_server + address = @@dns_config['address'] + port = @@dns_config['port'] + + @@dns.run_server(address, port) + sleep(3) + end + + # Tests procedure for adding new DNS rules + def test_5_add_rule + id = nil + same_id = nil + + domain = 'foo.bar' + response = '1.2.3.4' + + # Add a new rule normally + assert_nothing_raised do + id = @@dns.add_rule(domain, IN::A) do |transaction| + transaction.respond!(response) + end + end + + assert_not_nil(id) + assert_equal(7, id.length) + + # Attempt to add an existing rule + assert_nothing_raised do + same_id = @@dns.add_rule(domain, IN::A) do |transaction| + transaction.respond!(response) + end + end + + assert_not_nil(same_id) + assert_equal(same_id, id) + end + end