summaryrefslogtreecommitdiffstats
path: root/roles/openshift_health_checker/test/action_plugin_test.py
blob: 9667dc803a363f222c80a0e1b6e0c8745678b95c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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)