From 5769615cd58a94caece0a0581b19ba893ae0a78a Mon Sep 17 00:00:00 2001 From: soh_cah_toa Date: Mon, 15 Jul 2013 03:48:01 -0400 Subject: [PATCH] Added unit tests for #get_rule. Also removed convenience variables from #add_rule tests (domain and response). The "response" key in the hash returned by #get_rule is generated by Sourcify which sourcifies the variable name, not its value. --- test/unit/extensions/tc_dns.rb | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/test/unit/extensions/tc_dns.rb b/test/unit/extensions/tc_dns.rb index a4a75a4e3..fe4705d36 100644 --- a/test/unit/extensions/tc_dns.rb +++ b/test/unit/extensions/tc_dns.rb @@ -68,13 +68,12 @@ class TC_Dns < Test::Unit::TestCase 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) + id = @@dns.add_rule('foo.bar', IN::A) do |transaction| + transaction.respond!('1.2.3.4') end end @@ -83,8 +82,8 @@ class TC_Dns < Test::Unit::TestCase # Attempt to add an existing rule assert_nothing_raised do - same_id = @@dns.add_rule(domain, IN::A) do |transaction| - transaction.respond!(response) + same_id = @@dns.add_rule('foo.bar', IN::A) do |transaction| + transaction.respond!('1.2.3.4') end end @@ -92,4 +91,28 @@ class TC_Dns < Test::Unit::TestCase assert_equal(same_id, id) end + # Tests retrieval of DNS rules + def test_6_get_rule + id = @@dns.add_rule('be.ef', IN::A) do |transaction| + transaction.respond!('1.1.1.1') + end + + rule = @@dns.get_rule(id) + + assert(rule.has_key?(:id)) + assert(rule.has_key?(:pattern)) + assert(rule.has_key?(:type)) + assert(rule.has_key?(:response)) + + assert_equal(id, rule[:id]) + assert_equal('be.ef', rule[:pattern]) + assert_equal('A', rule[:type]) + + response = rule[:response] + + assert_equal(Array, response.class) + assert(response.length > 0) + assert_equal('1.1.1.1', response[0]) + end + end