summaryrefslogtreecommitdiff
path: root/lib/custodian/testfactory.rb
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2012-11-22 11:13:51 +0000
committerSteve Kemp <steve@steve.org.uk>2012-11-22 11:13:51 +0000
commita00e6b8537de27da16a4ede8466233be4e1b8c8c (patch)
tree8fb428956622af9be6a8da5637757069a2ba8a12 /lib/custodian/testfactory.rb
parente0d947b217aed5e06355ff3c9512dbcea563564c (diff)
Moved TestFactory to the custodian-namespace.
Diffstat (limited to 'lib/custodian/testfactory.rb')
-rw-r--r--lib/custodian/testfactory.rb106
1 files changed, 55 insertions, 51 deletions
diff --git a/lib/custodian/testfactory.rb b/lib/custodian/testfactory.rb
index c736ac1..5b2428d 100644
--- a/lib/custodian/testfactory.rb
+++ b/lib/custodian/testfactory.rb
@@ -13,75 +13,79 @@ require 'json'
# file - or that line encoded as a JSON string.
#
#
-class TestFactory
+module Custodian
- #
- # The subclasses we have.
- #
- @@subclasses = { }
+ class TestFactory
- #
- # Create a test-type object given a line of text from our parser.
- #
- # The line will be like "target must run tcp|ssh|ftp|smtp .."
- #
- #
- def self.create( line )
-
#
- # JSON ?
+ # The subclasses we have.
#
- if ( line =~ /^\{(.*)\}$/ )
- begin
- obj = JSON.parse( line );
- raise ArgumentError, "JSON object was not a hash" unless obj.kind_of?(Hash)
- line = obj["line"]
- raise ArgumentError, "obj[:line] was nil" unless (!line.nil?)
- rescue =>ex
- raise ArgumentError, "Line did not deserialize from JSON: #{line} - #{ex}"
- end
- end
+ @@subclasses = { }
#
- # If this is an obvious protocol test.
+ # Create a test-type object given a line of text from our parser.
#
- if ( line =~ /must\s+run\s+(\S+)(\s+|\.|$)/ )
- test_type = $1.dup
- test_type.chomp!( "." )
+ # The line will be like "target must run tcp|ssh|ftp|smtp .."
+ #
+ #
+ def self.create( line )
+
+ #
+ # JSON ?
+ #
+ if ( line =~ /^\{(.*)\}$/ )
+ begin
+ obj = JSON.parse( line );
+ raise ArgumentError, "JSON object was not a hash" unless obj.kind_of?(Hash)
+ line = obj["line"]
+ raise ArgumentError, "obj[:line] was nil" unless (!line.nil?)
+ rescue =>ex
+ raise ArgumentError, "Line did not deserialize from JSON: #{line} - #{ex}"
+ end
+ end
- c = @@subclasses[test_type]
- if c
- c.new( line )
+
+ #
+ # If this is an obvious protocol test.
+ #
+ if ( line =~ /must\s+run\s+(\S+)(\s+|\.|$)/ )
+ test_type = $1.dup
+ test_type.chomp!( "." )
+
+ c = @@subclasses[test_type]
+ if c
+ c.new( line )
+ else
+ raise ArgumentError, "Bad test type: #{test_type}"
+ end
else
- raise ArgumentError, "Bad test type: #{test_type}"
+ raise "Unknown line given - Failed to instantiate a suitable protocol-test."
end
- else
- raise "Unknown line given - Failed to instantiate a suitable protocol-test."
end
- end
- #
- # Register a new test type - this must be called by our derived classes
- #
- def self.register_test_type name
- @@subclasses[name] = self
- end
+ #
+ # Register a new test type - this must be called by our derived classes
+ #
+ def self.register_test_type name
+ @@subclasses[name] = self
+ end
- #
- # Return an array of test-types we know about
- #
- # i.e. Derived classes that have registered themselves.
- #
- #
- def types
- @@subclasses
- end
+ #
+ # Return an array of test-types we know about
+ #
+ # i.e. Derived classes that have registered themselves.
+ #
+ #
+ def types
+ @@subclasses
+ end
-end
+ end
+end