test_extra_minion_data_in_pillar.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from salt.pillar import extra_minion_data_in_pillar
  2. from tests.support.mixins import LoaderModuleMockMixin
  3. from tests.support.mock import MagicMock
  4. from tests.support.unit import TestCase
  5. class ExtraMinionDataInPillarTestCase(TestCase, LoaderModuleMockMixin):
  6. """
  7. Test cases for salt.pillar.extra_minion_data_in_pillar
  8. """
  9. def setup_loader_modules(self):
  10. return {extra_minion_data_in_pillar: {}}
  11. def setUp(self):
  12. self.pillar = MagicMock()
  13. self.extra_minion_data = {
  14. "key1": {"subkey1": "value1"},
  15. "key2": {"subkey2": {"subsubkey2": "value2"}},
  16. "key3": "value3",
  17. "key4": {"subkey4": "value4"},
  18. }
  19. def test_extra_values_none_or_empty(self):
  20. ret = extra_minion_data_in_pillar.ext_pillar(
  21. "fake_id", self.pillar, "fake_include", None
  22. )
  23. self.assertEqual(ret, {})
  24. ret = extra_minion_data_in_pillar.ext_pillar(
  25. "fake_id", self.pillar, "fake_include", {}
  26. )
  27. self.assertEqual(ret, {})
  28. def test_include_all(self):
  29. for include_all in ["*", "<all>"]:
  30. ret = extra_minion_data_in_pillar.ext_pillar(
  31. "fake_id", self.pillar, include_all, self.extra_minion_data
  32. )
  33. self.assertEqual(ret, self.extra_minion_data)
  34. def test_include_specific_keys(self):
  35. # Tests partially existing key, key with and without subkey,
  36. ret = extra_minion_data_in_pillar.ext_pillar(
  37. "fake_id",
  38. self.pillar,
  39. include=["key1:subkey1", "key2:subkey3", "key3", "key4"],
  40. extra_minion_data=self.extra_minion_data,
  41. )
  42. self.assertEqual(
  43. ret,
  44. {
  45. "key1": {"subkey1": "value1"},
  46. "key3": "value3",
  47. "key4": {"subkey4": "value4"},
  48. },
  49. )