forked from openshift/openshift-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for existing health checks
- Loading branch information
1 parent
c73bb3a
commit 8cfdd96
Showing
4 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import os | ||
import sys | ||
|
||
# extend sys.path so that tests can import openshift_checks | ||
sys.path.insert(1, os.path.dirname(os.path.dirname(__file__))) |
40 changes: 40 additions & 0 deletions
40
roles/openshift_health_checker/test/openshift_check_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |