test_saltclass.py 2.3 KB

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