salt/tests/unit/states/test_chef.py

70 lines
1.9 KiB
Python
Raw Normal View History

2015-04-27 11:38:56 +00:00
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
'''
# Import Python libs
2018-01-19 18:48:35 +00:00
from __future__ import absolute_import, print_function, unicode_literals
2015-04-27 11:38:56 +00:00
# Import Salt Testing Libs
2017-03-22 16:42:17 +00:00
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import skipIf, TestCase
from tests.support.mock import (
2015-04-27 11:38:56 +00:00
NO_MOCK,
NO_MOCK_REASON,
MagicMock,
patch)
# Import Salt Libs
import salt.states.chef as chef
2015-04-27 11:38:56 +00:00
@skipIf(NO_MOCK, NO_MOCK_REASON)
2017-03-22 16:42:17 +00:00
class ChefTestCase(TestCase, LoaderModuleMockMixin):
2015-04-27 11:38:56 +00:00
'''
Test cases for salt.states.chef
'''
2017-03-22 16:42:17 +00:00
def setup_loader_modules(self):
return {chef: {}}
2015-04-27 11:38:56 +00:00
# 'client' function tests: 1
def test_client(self):
'''
Test to run chef-client
'''
name = 'my-chef-run'
ret = {'name': name,
'result': False,
'changes': {},
'comment': ''}
mock = MagicMock(return_value={'retcode': 1, 'stdout': '',
'stderr': 'error'})
with patch.dict(chef.__salt__, {'chef.client': mock}):
with patch.dict(chef.__opts__, {'test': True}):
comt = ('\nerror')
ret.update({'comment': comt})
self.assertDictEqual(chef.client(name), ret)
# 'solo' function tests: 1
def test_solo(self):
'''
Test to run chef-solo
'''
name = 'my-chef-run'
ret = {'name': name,
'result': False,
'changes': {},
'comment': ''}
mock = MagicMock(return_value={'retcode': 1, 'stdout': '',
'stderr': 'error'})
with patch.dict(chef.__salt__, {'chef.solo': mock}):
with patch.dict(chef.__opts__, {'test': True}):
comt = ('\nerror')
ret.update({'comment': comt})
self.assertDictEqual(chef.solo(name), ret)