summaryrefslogtreecommitdiff
path: root/lib/custodian
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2015-04-16 16:11:24 +0100
committerSteve Kemp <steve@steve.org.uk>2015-04-16 16:11:24 +0100
commit1c9796068cdf0afe4af1b781a8b8b20b0c8a26d3 (patch)
treeb2d1d69019dc0979801d6c96d39666b810459975 /lib/custodian
parent2db89392e9e2f66e2e8bef8eb8855d405d5078a9 (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.
Diffstat (limited to 'lib/custodian')
-rw-r--r--lib/custodian/testfactory.rb59
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