test_cache.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. """
  3. unit tests for the cache runner
  4. """
  5. # Import Python Libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. # Import Salt Libs
  8. import salt.runners.cache as cache
  9. import salt.utils.master
  10. from tests.support.mixins import LoaderModuleMockMixin
  11. from tests.support.mock import patch
  12. # Import Salt Testing Libs
  13. from tests.support.runtests import RUNTIME_VARS
  14. from tests.support.unit import TestCase
  15. class CacheTest(TestCase, LoaderModuleMockMixin):
  16. """
  17. Validate the cache runner
  18. """
  19. def setup_loader_modules(self):
  20. return {
  21. cache: {
  22. "__opts__": {
  23. "cache": "localfs",
  24. "pki_dir": RUNTIME_VARS.TMP,
  25. "key_cache": True,
  26. }
  27. }
  28. }
  29. def test_grains(self):
  30. """
  31. test cache.grains runner
  32. """
  33. mock_minion = ["Larry"]
  34. mock_ret = {}
  35. self.assertEqual(cache.grains(minion=mock_minion), mock_ret)
  36. mock_data = "grain stuff"
  37. class MockMaster(object):
  38. def __init__(self, *args, **kwargs):
  39. pass
  40. def get_minion_grains(self):
  41. return mock_data
  42. with patch.object(salt.utils.master, "MasterPillarUtil", MockMaster):
  43. self.assertEqual(cache.grains(), mock_data)