From 3f0cb049f297a631593b43b5ac37183c3f95824c Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Fri, 23 Nov 2012 14:03:18 +0000 Subject: Test port-detection --- t/test-custodian-testfactory.rb | 74 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/t/test-custodian-testfactory.rb b/t/test-custodian-testfactory.rb index 7ef44b1..383b0f0 100755 --- a/t/test-custodian-testfactory.rb +++ b/t/test-custodian-testfactory.rb @@ -35,6 +35,7 @@ class TestTestFactory < Test::Unit::TestCase # Test the FTP-test may be created # def test_ftp_uri + assert_nothing_raised do assert( Custodian::TestFactory.create( "ftp.example.com must run ftp." ) ) assert( Custodian::TestFactory.create( "ftp://ftp.example.com/ must run ftp." ) ) @@ -47,11 +48,80 @@ class TestTestFactory < Test::Unit::TestCase assert( Custodian::TestFactory.create( "ftp://ftp.example.com/ must run ftp." ).target() == "ftp.example.com" ) + # + # Test the port detection + # + data = { + "foo must run ftp." => "21", + "ftp://ftp.example.com/ must run ftp." => "21", + "foo must run ftp on 1 otherwise 'x'." => "1", + "foo must run ftp on 33 otherwise" => "33", + } + + # + # Run each test + # + data.each do |str,prt| + assert_nothing_raised do + + obj = Custodian::TestFactory.create( str ) + + # + # Ensure we got the object, and the port was correct. + # + assert(obj, "created object via TestFactory.create('#{str}')") + assert( obj.port().to_s == prt , "'#{str}' gave expected port '#{prt}'.") + end + end + + end + + + + # + # Test the rsync-test creation. + # + def test_rsync_uri - assert( Custodian::TestFactory.create( "rsync.example.com must run rsync." ).target() == "rsync.example.com" ) - assert( Custodian::TestFactory.create( "rsync://rsync.example.com/ must run rsync." ).target() == "rsync.example.com" ) + assert_nothing_raised do + assert( Custodian::TestFactory.create( "example.com must run rsync." ) ) + assert( Custodian::TestFactory.create( "ftp://example.com/ must run rsync." ) ) + assert( Custodian::TestFactory.create( "ftp://example.com/ must run rsync on 333." ) ) + assert( Custodian::TestFactory.create( "ftp://example.com/ must run rsync on 3311 otherwise 'xxx'." ) ) + end + assert( Custodian::TestFactory.create( "rsync.example.com must run rsync." ).target() == + "rsync.example.com" ) + assert( Custodian::TestFactory.create( "rsync://rsync.example.com/ must run rsync." ).target() == + "rsync.example.com" ) + + + # + # Test the ports + # + data = { + "foo must run rsync." => "873", + "rsync://foo/ must run rsync." => "873", + "foo must run rsync on 1 otherwise 'x'." => "1", + "foo must run rsync on 33 otherwise" => "33", + } + + # + # Run each test + # + data.each do |str,prt| + assert_nothing_raised do + + obj = Custodian::TestFactory.create( str ) + + # + # Ensure we got the object, and the port was correct. + # + assert(obj, "created object via TestFactory.create('#{str}')") + assert( obj.port().to_s == prt , "'#{str}' gave expected port '#{prt}'.") + end + end end -- cgit v1.2.1