summaryrefslogtreecommitdiffstats
path: root/roles/openshift_health_checker/test/rpm_version_test.py
blob: 2f09ef9655fbd030c2a4ed60623b4c924c7405d1 (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
75
76
77
78
79
80
81
82
import pytest
import rpm_version

expected_pkgs = {
    "spam": {
        "name": "spam",
        "version": "3.2.1",
    },
    "eggs": {
        "name": "eggs",
        "version": "3.2.1",
    },
}


@pytest.mark.parametrize('pkgs, expect_not_found', [
    (
        {},
        ["spam", "eggs"],  # none found
    ),
    (
        {"spam": ["3.2.1", "4.5.1"]},
        ["eggs"],  # completely missing
    ),
    (
        {
            "spam": ["3.2.1", "4.5.1"],
            "eggs": ["3.2.1"],
        },
        [],  # all found
    ),
])
def test_check_pkg_found(pkgs, expect_not_found):
    if expect_not_found:
        with pytest.raises(rpm_version.RpmVersionException) as e:
            rpm_version._check_pkg_versions(pkgs, expected_pkgs)

        assert "not found to be installed" in str(e.value)
        assert set(expect_not_found) == set(e.value.problem_pkgs)
    else:
        rpm_version._check_pkg_versions(pkgs, expected_pkgs)


@pytest.mark.parametrize('pkgs, expect_not_found', [
    (
        {
            'spam': ['3.2.1'],
            'eggs': ['3.3.2'],
        },
        {
            "eggs": {
                "required_version": "3.2",
                "found_versions": ["3.3"],
            }
        },  # not the right version
    ),
    (
        {
            'spam': ['3.1.2', "3.3.2"],
            'eggs': ['3.3.2', "1.2.3"],
        },
        {
            "eggs": {
                "required_version": "3.2",
                "found_versions": ["3.3", "1.2"],
            },
            "spam": {
                "required_version": "3.2",
                "found_versions": ["3.1", "3.3"],
            }
        },  # not the right version
    ),
])
def test_check_pkg_version_found(pkgs, expect_not_found):
    if expect_not_found:
        with pytest.raises(rpm_version.RpmVersionException) as e:
            rpm_version._check_pkg_versions(pkgs, expected_pkgs)

        assert "found to be installed with an incorrect version" in str(e.value)
        assert expect_not_found == e.value.problem_pkgs
    else:
        rpm_version._check_pkg_versions(pkgs, expected_pkgs)