test_cache.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 Testing Libs
  8. from tests.support.runtime import RUNTIME_VARS
  9. from tests.support.mixins import LoaderModuleMockMixin
  10. from tests.support.unit import TestCase
  11. from tests.support.mock import (
  12. patch
  13. )
  14. # Import Salt Libs
  15. import salt.runners.cache as cache
  16. import salt.utils.master
  17. class CacheTest(TestCase, LoaderModuleMockMixin):
  18. '''
  19. Validate the cache runner
  20. '''
  21. def setup_loader_modules(self):
  22. return {cache: {'__opts__': {'cache': 'localfs', 'pki_dir': RUNTIME_VARS.TMP, 'key_cache': True}}}
  23. def test_grains(self):
  24. '''
  25. test cache.grains runner
  26. '''
  27. mock_minion = ['Larry']
  28. mock_ret = {}
  29. self.assertEqual(cache.grains(minion=mock_minion), mock_ret)
  30. mock_data = 'grain stuff'
  31. class MockMaster(object):
  32. def __init__(self, *args, **kwargs):
  33. pass
  34. def get_minion_grains(self):
  35. return mock_data
  36. with patch.object(salt.utils.master, 'MasterPillarUtil', MockMaster):
  37. self.assertEqual(cache.grains(), mock_data)