diff options
| author | Steve Kemp <steve@steve.org.uk> | 2012-11-25 22:19:29 +0000 | 
|---|---|---|
| committer | Steve Kemp <steve@steve.org.uk> | 2012-11-25 22:19:29 +0000 | 
| commit | e8c817c496a913dd2c9bd73073620a91c62646b4 (patch) | |
| tree | 98c422619b65055ebb4c99b482d562f930eacfd5 | |
| parent | 86b4458ea3523b8951c5712cd2472dcc242e1209 (diff) | |
  Parse the "otherwise 'xxxx'." part of the tests.
| -rw-r--r-- | lib/custodian/testfactory.rb | 36 | ||||
| -rwxr-xr-x | t/test-custodian-parser.rb | 44 | 
2 files changed, 78 insertions, 2 deletions
| diff --git a/lib/custodian/testfactory.rb b/lib/custodian/testfactory.rb index ccfc89e..603b69f 100644 --- a/lib/custodian/testfactory.rb +++ b/lib/custodian/testfactory.rb @@ -43,7 +43,19 @@ module Custodian          test_type.chomp!( "." )          c = @@subclasses[test_type]          if c -          c.new( line ) + +          obj = c.new( line ) + +          # +          # Get the notification text, which is not specific to the test-type +          # +          # We do this only after we've instantiated the test. +          # +          if ( line =~ /\s+otherwise\s+'([^']+)'/ ) +            obj.set_notification_text( $1.dup ) +          end + +          return obj          else            raise ArgumentError, "Bad test type: '#{test_type}'"          end @@ -94,6 +106,27 @@ module Custodian + +    # +    # Return the user-text which is returned on error +    # +    def get_notification_text +      @notification_text +    end + + + + +    # +    # Set the user-text which is returned on error. +    # +    def set_notification_text( str ) +      @notification_text = str +    end + + + +      #      #  Is this test inverted?      # @@ -102,6 +135,7 @@ module Custodian      end +      #      #  Return the port of this test.      # diff --git a/t/test-custodian-parser.rb b/t/test-custodian-parser.rb index 5017179..9b97262 100755 --- a/t/test-custodian-parser.rb +++ b/t/test-custodian-parser.rb @@ -230,7 +230,7 @@ EOF      #      in_txt  = "example.bytemark.co.uk must run smtp."      out_txt = parser.expand_macro( in_txt ) -     +      #      #  The difference is the return value will be an array      # @@ -260,4 +260,46 @@ EOF      assert( ret[1] =~ /example2/)    end + + + +  # +  # Test that the text we're going to use in alerters is present. +  # +  def test_alert_text + +    # +    # test data +    # +    data = { +      "foo must run rsync."                     => nil, +      "foo must not run ping."                  => nil, +      "foo must not run ssh otherwise 'fail'"   => "fail", +      "foo must not run ssh otherwise 'fail'."  => "fail", +      "foo must run ldap otherwise 'ldap dead?'" => "ldap dead?", +      "foo must run ping otherwise 'don't you love me?'" => "don" +    } + +    # +    #  For each test +    # +    data.each do |str,fail| +      assert_nothing_raised do + +        # +        # Create the new parser +        # +        obj = Custodian::TestFactory.create( str ) + +        assert(obj) + +        if ( fail.nil? ) +          assert( obj.get_notification_text().nil? ) +        else +          assert_equal( obj.get_notification_text(), fail ) +        end + +      end +    end +  end  end | 
