From 2adfccca3ac97bedeaec092ba621db17ac0cf004 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Thu, 11 Dec 2014 12:43:47 +0000 Subject: Moved test-dns-types so that it gets included in the test suite. Added test for run_test. --- t/test-dns-types | 61 ---------------------------------------- t/test-dns-types.rb | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 61 deletions(-) delete mode 100755 t/test-dns-types create mode 100755 t/test-dns-types.rb diff --git a/t/test-dns-types b/t/test-dns-types deleted file mode 100755 index dba7a3c..0000000 --- a/t/test-dns-types +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/ruby -Ilib/ -I../lib/ - - -require 'test/unit' - -require 'custodian/protocoltests' - - - -# -# The DNS test is a complex one. -# -class TestDNSTypes < Test::Unit::TestCase - - # - # Create the test suite environment: NOP. - # - def setup - end - - # - # Destroy the test suite environment: NOP. - # - def teardown - end - - - # - # Test the known-record types: A, NS, MX, AAAA - # - def test_known_types - - assert_nothing_raised do - test = Custodian::TestFactory.create( "a.ns.bytemark.co.uk must run dns for bytemark.co.uk resolving NS as 'foo'." ) - test = Custodian::TestFactory.create( "a.ns.bytemark.co.uk must run dns for bytemark.co.uk resolving A as 'foo'." ) - test = Custodian::TestFactory.create( "a.ns.bytemark.co.uk must run dns for bytemark.co.uk resolving MX as 'foo'." ) - test = Custodian::TestFactory.create( "a.ns.bytemark.co.uk must run dns for bytemark.co.uk resolving AAAA as 'foo'." ) - end - - end - - - - # - # Test that using random types fails. - # - def test_unknown_types - - # - # Each of these will fail - # - %w( a ns www example fdskfjdlfsj `` ).each do |res| - assert_raise ArgumentError do - Custodian::TestFactory.create( "a.ns.bytemark.co.uk must run dns for bytemark.co.uk resolving #{res} as 'foo'." ) - end - end - end - - -end - diff --git a/t/test-dns-types.rb b/t/test-dns-types.rb new file mode 100755 index 0000000..3f122e4 --- /dev/null +++ b/t/test-dns-types.rb @@ -0,0 +1,81 @@ +#!/usr/bin/ruby -Ilib/ -I../lib/ + + +require 'test/unit' +require 'mocha/test_unit' +require 'custodian/protocoltests' + + + +# +# The DNS test is a complex one. +# +class TestDNSTypes < Test::Unit::TestCase + + # + # Create the test suite environment: NOP. + # + def setup + end + + # + # Destroy the test suite environment: NOP. + # + def teardown + end + + + # + # Test the known-record types: A, NS, MX, AAAA + # + def test_known_types + + assert_nothing_raised do + test = Custodian::TestFactory.create( "a.ns.bytemark.co.uk must run dns for bytemark.co.uk resolving NS as 'foo'." ) + test = Custodian::TestFactory.create( "a.ns.bytemark.co.uk must run dns for bytemark.co.uk resolving A as 'foo'." ) + test = Custodian::TestFactory.create( "a.ns.bytemark.co.uk must run dns for bytemark.co.uk resolving MX as 'foo'." ) + test = Custodian::TestFactory.create( "a.ns.bytemark.co.uk must run dns for bytemark.co.uk resolving AAAA as 'foo'." ) + end + + end + + + + # + # Test that using random types fails. + # + def test_unknown_types + + # + # Each of these will fail + # + %w( a ns www example fdskfjdlfsj `` ).each do |res| + assert_raise ArgumentError do + Custodian::TestFactory.create( "a.ns.bytemark.co.uk must run dns for bytemark.co.uk resolving #{res} as 'foo'." ) + end + end + end + + # + # Now test the protocol stuff, without doing the resolution itself. + # + def test_dns_protocol_test + test = Custodian::TestFactory.create( "a.ns.bytemark.co.uk must run dns for bytemark.co.uk resolving A as '1.2.3.4,2001:lower::case,2001:UPPER::CASE'." ) + test.stubs(:resolve_via).returns(%w(2001:lower::case 2001:upper::case 1.2.3.4)) + assert test.run_test, test.error + + # Re-stub to return just one record + test.stubs(:resolve_via).returns(%w(1.2.3.4)) + assert !test.run_test + + # Re-stub to return too many records + test.stubs(:resolve_via).returns(%w(2001:lower::case 2001:upper::case 1.2.3.4 1.2.3.5)) + assert !test.run_test + + # Re-stub to return no records + test.stubs(:resolve_via).returns([]) + assert !test.run_test + end + +end + -- cgit v1.2.1