summaryrefslogtreecommitdiffstats
path: root/roles/openshift_health_checker/test
diff options
context:
space:
mode:
authorLuke Meyer <lmeyer@redhat.com>2017-07-28 07:19:24 -0400
committerLuke Meyer <lmeyer@redhat.com>2017-08-01 12:18:37 -0400
commit4e6bf287d97aaa254aeb8cf1d83b2229fee7a19f (patch)
tree4d2292c3b533c47693e03072f89720002a998223 /roles/openshift_health_checker/test
parentbf0bf407479458206f48885e43d3e1d3a2eab6e1 (diff)
downloadopenshift-4e6bf287d97aaa254aeb8cf1d83b2229fee7a19f.tar.gz
openshift-4e6bf287d97aaa254aeb8cf1d83b2229fee7a19f.tar.bz2
openshift-4e6bf287d97aaa254aeb8cf1d83b2229fee7a19f.tar.xz
openshift-4e6bf287d97aaa254aeb8cf1d83b2229fee7a19f.zip
openshift_checks: enable variable conversion
Diffstat (limited to 'roles/openshift_health_checker/test')
-rw-r--r--roles/openshift_health_checker/test/openshift_check_test.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/roles/openshift_health_checker/test/openshift_check_test.py b/roles/openshift_health_checker/test/openshift_check_test.py
index 43aa875f4..789784c77 100644
--- a/roles/openshift_health_checker/test/openshift_check_test.py
+++ b/roles/openshift_health_checker/test/openshift_check_test.py
@@ -81,6 +81,7 @@ def dummy_check(task_vars):
@pytest.mark.parametrize("keys,expected", [
(("foo",), 42),
(("bar", "baz"), "openshift"),
+ (("bar.baz",), "openshift"),
])
def test_get_var_ok(task_vars, keys, expected):
assert dummy_check(task_vars).get_var(*keys) == expected
@@ -94,3 +95,24 @@ def test_get_var_error(task_vars, missing_keys):
def test_get_var_default(task_vars, missing_keys):
default = object()
assert dummy_check(task_vars).get_var(*missing_keys, default=default) == default
+
+
+@pytest.mark.parametrize("keys, convert, expected", [
+ (("foo",), str, "42"),
+ (("foo",), float, 42.0),
+ (("bar", "baz"), bool, False),
+])
+def test_get_var_convert(task_vars, keys, convert, expected):
+ assert dummy_check(task_vars).get_var(*keys, convert=convert) == expected
+
+
+@pytest.mark.parametrize("keys, convert", [
+ (("bar", "baz"), int),
+ (("bar.baz"), float),
+ (("foo"), "bogus"),
+ (("foo"), lambda a, b: 1),
+ (("foo"), lambda a: 1 / 0),
+])
+def test_get_var_convert_error(task_vars, keys, convert):
+ with pytest.raises(OpenShiftCheckException):
+ dummy_check(task_vars).get_var(*keys, convert=convert)