summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2012-11-23 15:46:12 +0000
committerSteve Kemp <steve@steve.org.uk>2012-11-23 15:46:12 +0000
commit19ad4dc151720b6d172e2f3dabf11cce933ba18d (patch)
tree3c17d871d9ba42496ff23f05522b99bd43bcb7bb
parentcd1750251483f82cafdfb8e6a92242097b4929c4 (diff)
Removed duplicate member-variables for subclasses.
Allow test-inversion via "must not run".
-rw-r--r--lib/custodian/protocoltest/ftp.rb30
-rw-r--r--lib/custodian/protocoltest/jabber.rb27
-rw-r--r--lib/custodian/protocoltest/ldap.rb29
-rw-r--r--lib/custodian/protocoltest/ping.rb24
-rw-r--r--lib/custodian/protocoltest/rsync.rb30
-rw-r--r--lib/custodian/protocoltest/smtp.rb29
-rw-r--r--lib/custodian/protocoltest/ssh.rb31
-rw-r--r--lib/custodian/protocoltest/tcp.rb18
-rw-r--r--lib/custodian/testfactory.rb7
-rwxr-xr-xt/test-custodian-testfactory.rb30
10 files changed, 121 insertions, 134 deletions
diff --git a/lib/custodian/protocoltest/ftp.rb b/lib/custodian/protocoltest/ftp.rb
index a816bfd..25271c6 100644
--- a/lib/custodian/protocoltest/ftp.rb
+++ b/lib/custodian/protocoltest/ftp.rb
@@ -19,27 +19,6 @@ module Custodian
#
- # The line from which we were constructed.
- #
- attr_reader :line
-
-
- #
- # The host to test against.
- #
- attr_reader :host
-
-
- #
- # The port to connect to.
- #
- attr_reader :port
-
-
-
-
-
- #
# Constructor
#
def initialize( line )
@@ -58,6 +37,15 @@ module Custodian
end
#
+ # Is this test inverted?
+ #
+ if ( line =~ /must\s+not\s+run\s+/ )
+ @inverted = true
+ else
+ @inverted = false
+ end
+
+ #
# Save the port
#
if ( line =~ /on\s+([0-9]+)/ )
diff --git a/lib/custodian/protocoltest/jabber.rb b/lib/custodian/protocoltest/jabber.rb
index 9c0eb6d..1e95650 100644
--- a/lib/custodian/protocoltest/jabber.rb
+++ b/lib/custodian/protocoltest/jabber.rb
@@ -18,24 +18,6 @@ module Custodian
class JABBERTest < TCPTest
- #
- # The line from which we were constructed.
- #
- attr_reader :line
-
-
- #
- # The host to test against.
- #
- attr_reader :host
-
-
- #
- # The port to connect to.
- #
- attr_reader :port
-
-
#
# Constructor
@@ -53,6 +35,15 @@ module Custodian
@host = line.split( /\s+/)[0]
#
+ # Is this test inverted?
+ #
+ if ( line =~ /must\s+not\s+run\s+/ )
+ @inverted = true
+ else
+ @inverted = false
+ end
+
+ #
# Save the port
#
if ( line =~ /on\s+([0-9]+)/ )
diff --git a/lib/custodian/protocoltest/ldap.rb b/lib/custodian/protocoltest/ldap.rb
index b27e5d6..ab703e5 100644
--- a/lib/custodian/protocoltest/ldap.rb
+++ b/lib/custodian/protocoltest/ldap.rb
@@ -20,26 +20,6 @@ module Custodian
#
- # The line from which we were constructed.
- #
- attr_reader :line
-
-
- #
- # The host to test against.
- #
- attr_reader :host
-
-
- #
- # The port to connect to.
- #
- attr_reader :port
-
-
-
-
- #
# Constructor
#
def initialize( line )
@@ -55,6 +35,15 @@ module Custodian
@host = line.split( /\s+/)[0]
#
+ # Is this test inverted?
+ #
+ if ( line =~ /must\s+not\s+run\s+/ )
+ @inverted = true
+ else
+ @inverted = false
+ end
+
+ #
# Save the port
#
if ( line =~ /on\s+([0-9]+)/ )
diff --git a/lib/custodian/protocoltest/ping.rb b/lib/custodian/protocoltest/ping.rb
index c13c17c..95b387c 100644
--- a/lib/custodian/protocoltest/ping.rb
+++ b/lib/custodian/protocoltest/ping.rb
@@ -19,20 +19,6 @@ module Custodian
#
- # The line from which we were constructed.
- #
- attr_reader :line
-
-
- #
- # The host to test against.
- #
- attr_reader :host
-
-
-
-
- #
# Constructor
#
def initialize( line )
@@ -46,6 +32,16 @@ module Custodian
# Save the host
#
@host = line.split( /\s+/)[0]
+
+ #
+ # Is this test inverted?
+ #
+ if ( line =~ /must\s+not\s+run\s+/ )
+ @inverted = true
+ else
+ @inverted = false
+ end
+
end
diff --git a/lib/custodian/protocoltest/rsync.rb b/lib/custodian/protocoltest/rsync.rb
index 293f67c..3d38d3a 100644
--- a/lib/custodian/protocoltest/rsync.rb
+++ b/lib/custodian/protocoltest/rsync.rb
@@ -18,25 +18,6 @@ module Custodian
class RSYNCTest < TCPTest
- #
- # The line from which we were constructed.
- #
- attr_reader :line
-
-
- #
- # The host to test against.
- #
- attr_reader :host
-
-
- #
- # The port to connect to.
- #
- attr_reader :port
-
-
-
#
# Constructor
@@ -49,13 +30,22 @@ module Custodian
@line = line
#
- # Save the host
+ # If the target is an URL then strip to the hostname.
#
@host = line.split( /\s+/)[0]
if ( @host =~ /^rsync:\/\/([^\/]+)\/?/ )
@host = $1.dup
end
+ #
+ # Is this test inverted?
+ #
+ if ( line =~ /must\s+not\s+run\s+/ )
+ @inverted = true
+ else
+ @inverted = false
+ end
+
#
# Save the port
diff --git a/lib/custodian/protocoltest/smtp.rb b/lib/custodian/protocoltest/smtp.rb
index 0d22c95..89e2b24 100644
--- a/lib/custodian/protocoltest/smtp.rb
+++ b/lib/custodian/protocoltest/smtp.rb
@@ -20,26 +20,6 @@ module Custodian
#
- # The line from which we were constructed.
- #
- attr_reader :line
-
-
- #
- # The host to test against.
- #
- attr_reader :host
-
-
- #
- # The port to connect to.
- #
- attr_reader :port
-
-
-
-
- #
# Constructor
#
def initialize( line )
@@ -55,6 +35,15 @@ module Custodian
@host = line.split( /\s+/)[0]
#
+ # Is this test inverted?
+ #
+ if ( line =~ /must\s+not\s+run\s+/ )
+ @inverted = true
+ else
+ @inverted = false
+ end
+
+ #
# Save the port
#
if ( line =~ /on\s+([0-9]+)/ )
diff --git a/lib/custodian/protocoltest/ssh.rb b/lib/custodian/protocoltest/ssh.rb
index 205099e..0d64911 100644
--- a/lib/custodian/protocoltest/ssh.rb
+++ b/lib/custodian/protocoltest/ssh.rb
@@ -17,26 +17,6 @@ module Custodian
class SSHTest < TCPTest
-
- #
- # The line from which we were constructed.
- #
- attr_reader :line
-
-
- #
- # The host to test against.
- #
- attr_reader :host
-
-
- #
- # The port to connect to.
- #
- attr_reader :port
-
-
-
#
# Constructor
#
@@ -54,6 +34,17 @@ module Custodian
#
@host = line.split( /\s+/)[0]
+
+ #
+ # Is this test inverted?
+ #
+ if ( line =~ /must\s+not\s+run\s+/ )
+ @inverted = true
+ else
+ @inverted = false
+ end
+
+
#
# Save the port
#
diff --git a/lib/custodian/protocoltest/tcp.rb b/lib/custodian/protocoltest/tcp.rb
index c14f686..1aa9db4 100644
--- a/lib/custodian/protocoltest/tcp.rb
+++ b/lib/custodian/protocoltest/tcp.rb
@@ -23,7 +23,7 @@ module Custodian
#
- # The input line
+ # The input line from which we were constructed.
#
attr_reader :line
@@ -41,6 +41,12 @@ module Custodian
#
+ # Is this test inverted?
+ #
+ attr_reader :inverted
+
+
+ #
# The banner to look for, may be nil.
#
attr_reader :banner
@@ -65,6 +71,16 @@ module Custodian
#
@host = line.split( /\s+/)[0]
+
+ #
+ # Is this test inverted?
+ #
+ if ( line =~ /must\s+not\s+run\s+/ )
+ @inverted = true
+ else
+ @inverted = false
+ end
+
#
# Save the port
#
diff --git a/lib/custodian/testfactory.rb b/lib/custodian/testfactory.rb
index 934d6a7..6ae74d1 100644
--- a/lib/custodian/testfactory.rb
+++ b/lib/custodian/testfactory.rb
@@ -79,6 +79,13 @@ module Custodian
+ #
+ # Is this test inverted?
+ #
+ def inverted
+ @inverted
+ end
+
#
# Return the port of this test.
diff --git a/t/test-custodian-testfactory.rb b/t/test-custodian-testfactory.rb
index 9aeb6e1..db79f50 100755
--- a/t/test-custodian-testfactory.rb
+++ b/t/test-custodian-testfactory.rb
@@ -137,6 +137,36 @@ class TestTestFactory < Test::Unit::TestCase
assert( Custodian::TestFactory.create( "ftp://example.com/ must not run rsync." ) )
assert( Custodian::TestFactory.create( "ftp://example.com/ must not run rsync on 333." ) )
end
+
+
+ #
+ # Test some inversions
+ #
+ data = {
+ "foo must run rsync." => false,
+ "rsync://foo/ must run rsync." => false,
+ "foo must run ping otherwise" => false,
+ "foo must not run ping otherwise" => true,
+ "foo must not run ssh otherwise" => true,
+ "foo must not run ldap otherwise" => true,
+ }
+
+ #
+ # Run each test
+ #
+ data.each do |str,inv|
+ 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.inverted() == inv, "#{str} -> #{inv}" )
+ end
+ end
+
end
end