Module: check_mk
Branch: master
Commit: e26a935dca2eccec5e00939352f87d4c3a03ff0d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e26a935dca2ecc…
Author: Konstantin Büttner <kb(a)mathias-kettner.de>
Date: Mon Dec 18 11:44:50 2017 +0100
BasicCheckResult: Extract logic for matching status, infotext and perfdata into individual
methods
Change-Id: I8840a7679ea43a57974d63c93cb973791060e548
---
tests/checks/checktestlib.py | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/tests/checks/checktestlib.py b/tests/checks/checktestlib.py
index 32cad5d..221ce7b 100644
--- a/tests/checks/checktestlib.py
+++ b/tests/checks/checktestlib.py
@@ -1,4 +1,3 @@
-
class BasicCheckResult(object):
"""A basic check result
@@ -31,20 +30,32 @@ class BasicCheckResult(object):
assert all(type(value) in [int, float, type(None)] for value in
entry[2:])
self.perfdata = perfdata
+ def match_status(self, expected_status):
+ """Check if this result's status matches a given value. Exact
match."""
+ return self.status == expected_status
+
+ def match_infotext(self, expected_infotext):
+ """Check whether this result's infotext contains a given
string. Case-sensitive."""
+ return expected_infotext in self.infotext
+
+ def match_perfdata(self, expected_perfdata):
+ """Check whether this result's perfdata matches a given value.
Exact match."""
+ return expected_perfdata == self.perfdata
+
def assert_result(self, expected_result):
"""Assert that a result matches certain criteria
expected_result is a Dictionary defining the criteria, allowing to not
rigidly define every detail about the check result, but only what we
- really want to test.
+ really want to test. Unset fields mean we don't care.
"""
if "status" in expected_result:
- assert result.status == expected_result["status"]
+ assert match_status(expected_result["status"])
if "infotext" in expected_result:
- assert expected_result["infotext"] in result.infotext
+ assert match_infotext(expected_result["infotext"])
if "perfdata" in expected_result:
- assert result.perfdata == expected_result["perfdata"]
+ assert match_perfdata(expected_result["perfdata"])
class CompoundCheckResult(object):