summaryrefslogtreecommitdiffstats
path: root/roles/openshift_health_checker/test/curator_test.py
diff options
context:
space:
mode:
authorLuke Meyer <lmeyer@redhat.com>2017-07-20 23:39:47 -0400
committerLuke Meyer <lmeyer@redhat.com>2017-08-02 15:03:50 -0400
commit06a6fb9642a2cc70b1ca65f403b853fe8ce9d4b2 (patch)
tree4631e75c28017e238ff84756f6cfdeb72563259a /roles/openshift_health_checker/test/curator_test.py
parentbf0828bc0f2e3088df20abc77e30a162595e1c22 (diff)
downloadopenshift-06a6fb9642a2cc70b1ca65f403b853fe8ce9d4b2.tar.gz
openshift-06a6fb9642a2cc70b1ca65f403b853fe8ce9d4b2.tar.bz2
openshift-06a6fb9642a2cc70b1ca65f403b853fe8ce9d4b2.tar.xz
openshift-06a6fb9642a2cc70b1ca65f403b853fe8ce9d4b2.zip
openshift_checks: refactor logging checks
Turn failure messages into exceptions that tests can look for without depending on text meant for humans. Turn logging_namespace property into a method. Get rid of _exec_oc and just use logging.exec_oc.
Diffstat (limited to 'roles/openshift_health_checker/test/curator_test.py')
-rw-r--r--roles/openshift_health_checker/test/curator_test.py45
1 files changed, 17 insertions, 28 deletions
diff --git a/roles/openshift_health_checker/test/curator_test.py b/roles/openshift_health_checker/test/curator_test.py
index ae108c96e..62c680b74 100644
--- a/roles/openshift_health_checker/test/curator_test.py
+++ b/roles/openshift_health_checker/test/curator_test.py
@@ -1,22 +1,6 @@
import pytest
-from openshift_checks.logging.curator import Curator
-
-
-def canned_curator(exec_oc=None):
- """Create a Curator check object with canned exec_oc method"""
- check = Curator("dummy") # fails if a module is actually invoked
- if exec_oc:
- check._exec_oc = exec_oc
- return check
-
-
-def assert_error(error, expect_error):
- if expect_error:
- assert error
- assert expect_error in error
- else:
- assert not error
+from openshift_checks.logging.curator import Curator, OpenShiftCheckException
plain_curator_pod = {
@@ -44,25 +28,30 @@ not_running_curator_pod = {
}
+def test_get_curator_pods():
+ check = Curator()
+ check.get_pods_for_component = lambda *_: [plain_curator_pod]
+ result = check.run()
+ assert "failed" not in result or not result["failed"]
+
+
@pytest.mark.parametrize('pods, expect_error', [
(
[],
- "no Curator pods",
- ),
- (
- [plain_curator_pod],
- None,
+ 'MissingComponentPods',
),
(
[not_running_curator_pod],
- "not currently in a running state",
+ 'CuratorNotRunning',
),
(
[plain_curator_pod, plain_curator_pod],
- "more than one Curator pod",
+ 'TooManyCurators',
),
])
-def test_get_curator_pods(pods, expect_error):
- check = canned_curator()
- error = check.check_curator(pods)
- assert_error(error, expect_error)
+def test_get_curator_pods_fail(pods, expect_error):
+ check = Curator()
+ check.get_pods_for_component = lambda *_: pods
+ with pytest.raises(OpenShiftCheckException) as excinfo:
+ check.run()
+ assert excinfo.value.name == expect_error