diff options
author | Rodolfo Carvalho <rhcarvalho@gmail.com> | 2017-03-27 20:15:40 +0200 |
---|---|---|
committer | Rodolfo Carvalho <rhcarvalho@gmail.com> | 2017-04-04 17:59:53 +0200 |
commit | fe0dafda921b604f6a01e405b4a07df8aa340b03 (patch) | |
tree | 9541974622f23cab11b470ad8e7dfcccb563fa5a /roles/openshift_health_checker/test/action_plugin_test.py | |
parent | 8503cd10fd1002f40667d5303b159ed321b5fb7a (diff) | |
download | openshift-fe0dafda921b604f6a01e405b4a07df8aa340b03.tar.gz openshift-fe0dafda921b604f6a01e405b4a07df8aa340b03.tar.bz2 openshift-fe0dafda921b604f6a01e405b4a07df8aa340b03.tar.xz openshift-fe0dafda921b604f6a01e405b4a07df8aa340b03.zip |
Make resolve_checks more strict
So that all names it return are directly usable, without checking for
existence.
Diffstat (limited to 'roles/openshift_health_checker/test/action_plugin_test.py')
-rw-r--r-- | roles/openshift_health_checker/test/action_plugin_test.py | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/roles/openshift_health_checker/test/action_plugin_test.py b/roles/openshift_health_checker/test/action_plugin_test.py new file mode 100644 index 000000000..9667dc803 --- /dev/null +++ b/roles/openshift_health_checker/test/action_plugin_test.py @@ -0,0 +1,74 @@ +import pytest + +from openshift_health_check import resolve_checks + + +class FakeCheck(object): + def __init__(self, name, tags=None): + self.name = name + self.tags = tags or [] + + +@pytest.mark.parametrize('names,all_checks,expected', [ + ([], [], set()), + ( + ['a', 'b'], + [ + FakeCheck('a'), + FakeCheck('b'), + ], + set(['a', 'b']), + ), + ( + ['a', 'b', '@group'], + [ + FakeCheck('from_group_1', ['group', 'another_group']), + FakeCheck('not_in_group', ['another_group']), + FakeCheck('from_group_2', ['preflight', 'group']), + FakeCheck('a'), + FakeCheck('b'), + ], + set(['a', 'b', 'from_group_1', 'from_group_2']), + ), +]) +def test_resolve_checks_ok(names, all_checks, expected): + assert resolve_checks(names, all_checks) == expected + + +@pytest.mark.parametrize('names,all_checks,words_in_exception,words_not_in_exception', [ + ( + ['testA', 'testB'], + [], + ['check', 'name', 'testA', 'testB'], + ['tag', 'group', '@'], + ), + ( + ['@group'], + [], + ['tag', 'name', 'group'], + ['check', '@'], + ), + ( + ['testA', 'testB', '@group'], + [], + ['check', 'name', 'testA', 'testB', 'tag', 'group'], + ['@'], + ), + ( + ['testA', 'testB', '@group'], + [ + FakeCheck('from_group_1', ['group', 'another_group']), + FakeCheck('not_in_group', ['another_group']), + FakeCheck('from_group_2', ['preflight', 'group']), + ], + ['check', 'name', 'testA', 'testB'], + ['tag', 'group', '@'], + ), +]) +def test_resolve_checks_failure(names, all_checks, words_in_exception, words_not_in_exception): + with pytest.raises(Exception) as excinfo: + resolve_checks(names, all_checks) + for word in words_in_exception: + assert word in str(excinfo.value) + for word in words_not_in_exception: + assert word not in str(excinfo.value) |