summaryrefslogtreecommitdiffstats
path: root/test/openshift_version_tests.py
blob: 393a4d6bafbd14c5f5d5f8f0f267c959727f9d6c (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
""" Tests for the openshift_version Ansible filter module. """
# pylint: disable=missing-docstring,invalid-name

import os
import sys
import unittest

sys.path = [os.path.abspath(os.path.dirname(__file__) + "/../filter_plugins/")] + sys.path

# pylint: disable=import-error
import openshift_version  # noqa: E402


class OpenShiftVersionTests(unittest.TestCase):

    openshift_version_filters = openshift_version.FilterModule()

    # Static tests for legacy filters.
    legacy_gte_tests = [{'name': 'oo_version_gte_3_1_or_1_1',
                         'positive_enterprise_version': '3.2.0',
                         'negative_enterprise_version': '3.0.0',
                         'positive_origin_version': '1.2.0',
                         'negative_origin_version': '1.0.0'},
                        {'name': 'oo_version_gte_3_1_1_or_1_1_1',
                         'positive_enterprise_version': '3.2.0',
                         'negative_enterprise_version': '3.1.0',
                         'positive_origin_version': '1.2.0',
                         'negative_origin_version': '1.1.0'},
                        {'name': 'oo_version_gte_3_2_or_1_2',
                         'positive_enterprise_version': '3.3.0',
                         'negative_enterprise_version': '3.1.0',
                         'positive_origin_version': '1.3.0',
                         'negative_origin_version': '1.1.0'},
                        {'name': 'oo_version_gte_3_3_or_1_3',
                         'positive_enterprise_version': '3.4.0',
                         'negative_enterprise_version': '3.2.0',
                         'positive_origin_version': '1.4.0',
                         'negative_origin_version': '1.2.0'},
                        {'name': 'oo_version_gte_3_4_or_1_4',
                         'positive_enterprise_version': '3.5.0',
                         'negative_enterprise_version': '3.3.0',
                         'positive_origin_version': '1.5.0',
                         'negative_origin_version': '1.3.0'},
                        {'name': 'oo_version_gte_3_5_or_1_5',
                         'positive_enterprise_version': '3.6.0',
                         'negative_enterprise_version': '3.4.0',
                         'positive_origin_version': '3.6.0',
                         'negative_origin_version': '1.4.0'}]

    def test_legacy_gte_filters(self):
        for test in self.legacy_gte_tests:
            for deployment_type in ['enterprise', 'origin']:
                # Test negative case per deployment_type
                self.assertFalse(
                    self.openshift_version_filters._filters[test['name']](
                        test["negative_{}_version".format(deployment_type)], deployment_type))
                # Test positive case per deployment_type
                self.assertTrue(
                    self.openshift_version_filters._filters[test['name']](
                        test["positive_{}_version".format(deployment_type)], deployment_type))

    def test_gte_filters(self):
        for major, minor_start, minor_end in self.openshift_version_filters.versions:
            for minor in range(minor_start, minor_end):
                # Test positive case
                self.assertTrue(
                    self.openshift_version_filters._filters["oo_version_gte_{}_{}".format(major, minor)](
                        "{}.{}".format(major, minor + 1)))
                # Test negative case
                self.assertFalse(
                    self.openshift_version_filters._filters["oo_version_gte_{}_{}".format(major, minor)](
                        "{}.{}".format(major, minor)))