Module: check_mk
Branch: master
Commit: 8a176bdedf1217c62af1a0345ce3bf3bc1f438ed
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8a176bdedf1217…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri May 25 16:58:55 2018 +0200
Add unit test for checks.do_status_data_inventory_for
Change-Id: I38b2d4a51ded165ff4882843cba2cee0a327ed33
---
cmk_base/checks.py | 1 +
tests/unit/cmk_base/test_checks.py | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/cmk_base/checks.py b/cmk_base/checks.py
index 08d7b3e..11f9075 100644
--- a/cmk_base/checks.py
+++ b/cmk_base/checks.py
@@ -793,6 +793,7 @@ def get_management_board_precedence(check_plugin_name):
return mgmt_board
+# TODO: Better move this function to config.py
def do_status_data_inventory_for(hostname):
rules = config.active_checks.get('cmk_inv')
if rules is None:
diff --git a/tests/unit/cmk_base/test_checks.py b/tests/unit/cmk_base/test_checks.py
index bb73fb2..6836472 100644
--- a/tests/unit/cmk_base/test_checks.py
+++ b/tests/unit/cmk_base/test_checks.py
@@ -1,5 +1,9 @@
+import pytest
+
import cmk_base.checks as checks
import cmk_base.discovery as discovery
+import cmk_base.config as config
+import cmk_base.rulesets as rulesets
def test_load_checks():
checks._initialize_data_structures()
@@ -43,3 +47,20 @@ def test_discoverable_tcp_checks():
assert "logwatch" in checks.discoverable_tcp_checks()
+(a)pytest.mark.parametrize("result,ruleset"eset", [
+ (False, None),
+ (False, []),
+ (False, [( None, [], rulesets.ALL_HOSTS, {} )]),
+ (False, [( {}, [], rulesets.ALL_HOSTS, {} )]),
+ (True, [( {"status_data_inventory": True}, [], rulesets.ALL_HOSTS, {} )]),
+ (False, [( {"status_data_inventory": False}, [], rulesets.ALL_HOSTS, {}
)]),
+])
+def test_do_status_data_inventory_for(monkeypatch, result, ruleset):
+ config.load_default_config()
+
+ monkeypatch.setattr(config, "all_hosts", ["abc"])
+ monkeypatch.setattr(config, "active_checks", {
+ "cmk_inv": ruleset,
+ })
+
+ assert checks.do_status_data_inventory_for("abc") == result