1
0

test_cache.py 1.3 KB

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