diff options
author | Steve Kemp <steve@steve.org.uk> | 2012-11-21 16:41:44 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2012-11-21 16:41:44 +0000 |
commit | 4b2febc3813a540f3733ec25777c4935dcfd59cb (patch) | |
tree | 448b2d9d3741bd521efefc4213b22b6a76079962 /lib/custodian/protocoltest.rb | |
parent | 993cf89e87cf53bc003b5a8f1377910f1f115e9f (diff) |
Added stub for class-factory + test objects.
Diffstat (limited to 'lib/custodian/protocoltest.rb')
-rw-r--r-- | lib/custodian/protocoltest.rb | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/lib/custodian/protocoltest.rb b/lib/custodian/protocoltest.rb new file mode 100644 index 0000000..271e64c --- /dev/null +++ b/lib/custodian/protocoltest.rb @@ -0,0 +1,66 @@ + +# +# +# Base class for custodian protocol-tests +# +# Each subclass will register themselves, via the call +# to 'register_test_type'. +# +# This class is a factory that will return the correct +# derived class for a given line from our configuration +# file. +# +# +class ProtocolTest + + + # + # The subclasses we have. + # + @@subclasses = { } + + + # + # 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 ) + 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 "Uknown line given" + 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 + + + # + # Return an array of test-types we know about + # + # i.e. Derived classes that have registered themselves. + # + # + def types + @@subclasses + end + + +end + |