test_saltclass.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. import os
  5. # Import Salt Testing libs
  6. from tests.support.mixins import LoaderModuleMockMixin
  7. from tests.support.unit import TestCase, skipIf
  8. from tests.support.mock import NO_MOCK, NO_MOCK_REASON
  9. # Import Salt Libs
  10. import salt.pillar.saltclass as saltclass
  11. base_path = os.path.dirname(os.path.realpath(__file__))
  12. fake_minion_id = 'fake_id'
  13. fake_pillar = {}
  14. fake_args = ({'path': os.path.abspath(
  15. os.path.join(base_path, '..', '..', 'integration',
  16. 'files', 'saltclass', 'examples'))})
  17. fake_opts = {}
  18. fake_salt = {}
  19. fake_grains = {}
  20. @skipIf(NO_MOCK, NO_MOCK_REASON)
  21. class SaltclassPillarTestCase(TestCase, LoaderModuleMockMixin):
  22. '''
  23. Tests for salt.pillar.saltclass
  24. '''
  25. def setup_loader_modules(self):
  26. return {saltclass: {'__opts__': fake_opts,
  27. '__salt__': fake_salt,
  28. '__grains__': fake_grains}}
  29. def _runner(self, expected_ret):
  30. try:
  31. full_ret = saltclass.ext_pillar(fake_minion_id, fake_pillar, fake_args)
  32. parsed_ret = full_ret['__saltclass__']['classes']
  33. # Fail the test if we hit our NoneType error
  34. except TypeError as err:
  35. self.fail(err)
  36. # Else give the parsed content result
  37. self.assertListEqual(parsed_ret, expected_ret)
  38. def test_succeeds(self):
  39. ret = ['default.users', 'default.motd', 'default.empty', 'default', 'roles.app']
  40. self._runner(ret)
  41. @skipIf(NO_MOCK, NO_MOCK_REASON)
  42. class SaltclassPillarTestCaseListExpansion(TestCase, LoaderModuleMockMixin):
  43. '''
  44. Tests for salt.pillar.saltclass variable expansion in list
  45. '''
  46. def setup_loader_modules(self):
  47. return {saltclass: {'__opts__': fake_opts,
  48. '__salt__': fake_salt,
  49. '__grains__': fake_grains
  50. }}
  51. def _runner(self, expected_ret):
  52. full_ret = {}
  53. parsed_ret = []
  54. try:
  55. full_ret = saltclass.ext_pillar(fake_minion_id, fake_pillar, fake_args)
  56. parsed_ret = full_ret['test_list']
  57. # Fail the test if we hit our NoneType error
  58. except TypeError as err:
  59. self.fail(err)
  60. # Else give the parsed content result
  61. self.assertListEqual(parsed_ret, expected_ret)
  62. def test_succeeds(self):
  63. ret = [{'a': '192.168.10.10'}, '192.168.10.20']
  64. self._runner(ret)