test_chef.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
  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.unit import TestCase
  10. from tests.support.mock import (
  11. MagicMock,
  12. patch,
  13. )
  14. # Import Salt Libs
  15. import salt.modules.chef as chef
  16. class ChefTestCase(TestCase, LoaderModuleMockMixin):
  17. '''
  18. Test cases for salt.modules.chef
  19. '''
  20. def setup_loader_modules(self):
  21. patcher = patch('salt.utils.path.which', MagicMock(return_value=True))
  22. patcher.start()
  23. self.addCleanup(patcher.stop)
  24. return {chef: {'_exec_cmd': MagicMock(return_value={})}}
  25. # 'client' function tests: 1
  26. def test_client(self):
  27. '''
  28. Test if it execute a chef client run and return a dict
  29. '''
  30. with patch.dict(chef.__opts__, {'cachedir': r'c:\salt\var\cache\salt\minion'}):
  31. self.assertDictEqual(chef.client(), {})
  32. # 'solo' function tests: 1
  33. def test_solo(self):
  34. '''
  35. Test if it execute a chef solo run and return a dict
  36. '''
  37. with patch.dict(chef.__opts__, {'cachedir': r'c:\salt\var\cache\salt\minion'}):
  38. self.assertDictEqual(chef.solo('/dev/sda1'), {})