summaryrefslogtreecommitdiffstats
path: root/roles/openshift_health_checker/test/openshift_check_test.py
diff options
context:
space:
mode:
authorRodolfo Carvalho <rhcarvalho@gmail.com>2017-03-17 10:34:57 +0100
committerRodolfo Carvalho <rhcarvalho@gmail.com>2017-03-17 10:34:57 +0100
commit8cfdd96ffa1c5b35455751aa8be5a5704d2550da (patch)
treec742852afa7c703550cb26e11b0251f90807f6ca /roles/openshift_health_checker/test/openshift_check_test.py
parentc73bb3aa5b2b28ddbdf48f9735b5afa1b8228cd6 (diff)
downloadopenshift-8cfdd96ffa1c5b35455751aa8be5a5704d2550da.tar.gz
openshift-8cfdd96ffa1c5b35455751aa8be5a5704d2550da.tar.bz2
openshift-8cfdd96ffa1c5b35455751aa8be5a5704d2550da.tar.xz
openshift-8cfdd96ffa1c5b35455751aa8be5a5704d2550da.zip
Add unit tests for existing health checks
Diffstat (limited to 'roles/openshift_health_checker/test/openshift_check_test.py')
-rw-r--r--roles/openshift_health_checker/test/openshift_check_test.py40
1 files changed, 40 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
new file mode 100644
index 000000000..c4c8cd1c2
--- /dev/null
+++ b/roles/openshift_health_checker/test/openshift_check_test.py
@@ -0,0 +1,40 @@
+import pytest
+
+from openshift_checks import get_var, OpenShiftCheckException
+
+
+# Fixtures
+
+
+@pytest.fixture()
+def task_vars():
+ return dict(foo=42, bar=dict(baz="openshift"))
+
+
+@pytest.fixture(params=[
+ ("notfound",),
+ ("multiple", "keys", "not", "in", "task_vars"),
+])
+def missing_keys(request):
+ return request.param
+
+
+# Tests
+
+
+@pytest.mark.parametrize("keys,expected", [
+ (("foo",), 42),
+ (("bar", "baz"), "openshift"),
+])
+def test_get_var_ok(task_vars, keys, expected):
+ assert get_var(task_vars, *keys) == expected
+
+
+def test_get_var_error(task_vars, missing_keys):
+ with pytest.raises(OpenShiftCheckException):
+ get_var(task_vars, *missing_keys)
+
+
+def test_get_var_default(task_vars, missing_keys):
+ default = object()
+ assert get_var(task_vars, *missing_keys, default=default) == default