Module: check_mk
Branch: master
Commit: 03928aa0254185e7474a403364fc2c355129eeb5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=03928aa0254185…
Author: Konstantin Büttner <kb(a)mathias-kettner.de>
Date: Mon Feb 5 16:29:20 2018 +0100
Fix classes for discovery results in checktestlib, make tests for df discovery use them
Change-Id: I3d308f36d15d1edbdc96c9202d28270f2f3d9551
---
tests/checks/checktestlib.py | 13 +++++++++++--
tests/checks/test_df_check.py | 2 +-
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/tests/checks/checktestlib.py b/tests/checks/checktestlib.py
index 109d9f7..8092a91 100644
--- a/tests/checks/checktestlib.py
+++ b/tests/checks/checktestlib.py
@@ -16,6 +16,10 @@ class Tuploid(object):
def tuple(self):
raise NotImplementedError()
+ def __iter__(self):
+ for x in self.tuple:
+ yield x
+
class PerfValue(Tuploid):
"""Represents a single perf value"""
@@ -132,12 +136,13 @@ class DiscoveryEntry(Tuploid):
def __init__(self, entry):
item, default_params = entry
- assert type(item) in [ str. types.NoneType ]
+ assert type(item) in [ str, unicode, types.NoneType ]
self.item = item
self.default_params = default_params
+ @property
def tuple(self):
- return (item, default_params)
+ return (self.item, self.default_params)
class DiscoveryResult(object):
@@ -146,3 +151,7 @@ class DiscoveryResult(object):
self.entries = []
for entry in result:
self.entries.append(DiscoveryEntry(entry))
+
+ def __eq__(self, other_value):
+ return all(entry in other_value for entry in self.entries) and \
+ all(other_entry in self.entries for other_entry in other_value)
diff --git a/tests/checks/test_df_check.py b/tests/checks/test_df_check.py
index bd0b8ff..1681b5c 100644
--- a/tests/checks/test_df_check.py
+++ b/tests/checks/test_df_check.py
@@ -250,7 +250,7 @@ def test_df_discovery_with_parse(check_manager, monkeypatch, info,
expected_resu
check = check_manager.get_check("df")
monkeypatch.setitem(check.context, "host_extra_conf_merged", lambda _, __:
inventory_df_rules)
- assert check.run_discovery(check.run_parse(info)) == expected_result
+ assert checktestlib.DiscoveryResult(check.run_discovery(check.run_parse(info))) ==
expected_result
@pytest.mark.parametrize("item,params,info,expected_result", [