openshift_version_tests.py 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. """ Tests for the openshift_version Ansible filter module. """
  2. # pylint: disable=missing-docstring,invalid-name
  3. import os
  4. import sys
  5. import unittest
  6. sys.path = [os.path.abspath(os.path.dirname(__file__) + "/../filter_plugins/")] + sys.path
  7. # pylint: disable=import-error
  8. import openshift_version # noqa: E402
  9. class OpenShiftVersionTests(unittest.TestCase):
  10. openshift_version_filters = openshift_version.FilterModule()
  11. # Static tests for legacy filters.
  12. legacy_gte_tests = [{'name': 'oo_version_gte_3_1_or_1_1',
  13. 'positive_openshift-enterprise_version': '3.2.0',
  14. 'negative_openshift-enterprise_version': '3.0.0',
  15. 'positive_origin_version': '1.2.0',
  16. 'negative_origin_version': '1.0.0'},
  17. {'name': 'oo_version_gte_3_1_1_or_1_1_1',
  18. 'positive_openshift-enterprise_version': '3.2.0',
  19. 'negative_openshift-enterprise_version': '3.1.0',
  20. 'positive_origin_version': '1.2.0',
  21. 'negative_origin_version': '1.1.0'},
  22. {'name': 'oo_version_gte_3_2_or_1_2',
  23. 'positive_openshift-enterprise_version': '3.3.0',
  24. 'negative_openshift-enterprise_version': '3.1.0',
  25. 'positive_origin_version': '1.3.0',
  26. 'negative_origin_version': '1.1.0'},
  27. {'name': 'oo_version_gte_3_3_or_1_3',
  28. 'positive_openshift-enterprise_version': '3.4.0',
  29. 'negative_openshift-enterprise_version': '3.2.0',
  30. 'positive_origin_version': '1.4.0',
  31. 'negative_origin_version': '1.2.0'},
  32. {'name': 'oo_version_gte_3_4_or_1_4',
  33. 'positive_openshift-enterprise_version': '3.5.0',
  34. 'negative_openshift-enterprise_version': '3.3.0',
  35. 'positive_origin_version': '1.5.0',
  36. 'negative_origin_version': '1.3.0'},
  37. {'name': 'oo_version_gte_3_5_or_1_5',
  38. 'positive_openshift-enterprise_version': '3.6.0',
  39. 'negative_openshift-enterprise_version': '3.4.0',
  40. 'positive_origin_version': '3.6.0',
  41. 'negative_origin_version': '1.4.0'}]
  42. def test_legacy_gte_filters(self):
  43. for test in self.legacy_gte_tests:
  44. for deployment_type in ['openshift-enterprise', 'origin']:
  45. # Test negative case per deployment_type
  46. self.assertFalse(
  47. self.openshift_version_filters._filters[test['name']](
  48. test["negative_{}_version".format(deployment_type)], deployment_type))
  49. # Test positive case per deployment_type
  50. self.assertTrue(
  51. self.openshift_version_filters._filters[test['name']](
  52. test["positive_{}_version".format(deployment_type)], deployment_type))
  53. def test_gte_filters(self):
  54. for major, minor_start, minor_end in self.openshift_version_filters.versions:
  55. for minor in range(minor_start, minor_end):
  56. # Test positive case
  57. self.assertTrue(
  58. self.openshift_version_filters._filters["oo_version_gte_{}_{}".format(major, minor)](
  59. "{}.{}".format(major, minor + 1)))
  60. # Test negative case
  61. self.assertFalse(
  62. self.openshift_version_filters._filters["oo_version_gte_{}_{}".format(major, minor)](
  63. "{}.{}".format(major, minor)))
  64. def test_get_filters(self):
  65. self.assertTrue(
  66. self.openshift_version_filters.filters() == self.openshift_version_filters._filters)