diff options
| author | Steve Kemp <steve@steve.org.uk> | 2015-04-16 16:11:24 +0100 | 
|---|---|---|
| committer | Steve Kemp <steve@steve.org.uk> | 2015-04-16 16:11:24 +0100 | 
| commit | de7e0e2471026602725d8c0647f09aa0089f6a80 (patch) | |
| tree | c3624f56c72f233510b3019dd1afc65aacf983c2 | |
| parent | 3627b5ebd9c64e1b5b47dcd8222340ba1a0b461b (diff) | |
Updated to use types for test-returns.
This commit introduces a major change in custodian.  In the past
any test had either two results:
* return false - The test failed.
* return true  - The test passed.
We're now using an enum, more or less, such that a test may return a
"skipped" result which will neither raise nor clear any alert(s).
This is useful in its own right but is being introduced specifically
to allow SSL-certificate tests to avoid raising and clearing outside
working days/hours.
This closes #10328.
This fixes #10328.
| -rw-r--r-- | lib/custodian/testfactory.rb | 59 | 
1 files changed, 44 insertions, 15 deletions
| diff --git a/lib/custodian/testfactory.rb b/lib/custodian/testfactory.rb index 57bb1f7..29d1f99 100644 --- a/lib/custodian/testfactory.rb +++ b/lib/custodian/testfactory.rb @@ -1,19 +1,36 @@ - -# -# -# 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. -# -#  module Custodian + +  # +  #  The result of a single test: +  # +  #  If a test returns "TEST_FAILED" an alert will be raised. +  # +  #  If a test returns "TEST_PASSED" any outstanding alert will clear. +  # +  #  If a test returns "TEST_SKIPPED" NEITHER of those things will happen. +  # +  class TestResult +    TEST_PASSED  = 2 +    TEST_FAILED  = 4 +    TEST_SKIPPED = 8 +  end + + + +  # +  # +  # 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 TestFactory @@ -35,7 +52,10 @@ module Custodian        raise ArgumentError, 'The type of test to create must be a string' unless  line.kind_of? String        # -      #  The array we return. +      #  The array of tests we return. +      # +      #  This is required because a single test-definition may result in +      # multiple tests being executed.        #        result = [] @@ -70,6 +90,11 @@ module Custodian                obj.set_notification_text($1.dup)              end +            # +            # Is the test inverted? +            # +            obj.set_inverted(line =~ /must\s+not\s+run/ ? true : false) +              result.push(obj)            else              raise ArgumentError, "Bad test type: '#{test_type}'" @@ -155,7 +180,11 @@ module Custodian      #      #  Is this test inverted?      # -    def inverted +    def set_inverted(val) +      @inverted = val +    end + +    def inverted?        @inverted      end | 
