mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #24446 from jayeshka/rabbitmq_plugin_states-unit-test
adding states/rabbitmq_plugin unit test case.
This commit is contained in:
commit
8445a3f28d
1 changed files with 86 additions and 0 deletions
86
tests/unit/states/rabbitmq_plugin_test.py
Normal file
86
tests/unit/states/rabbitmq_plugin_test.py
Normal file
|
@ -0,0 +1,86 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from salttesting import skipIf, TestCase
|
||||
from salttesting.mock import (
|
||||
NO_MOCK,
|
||||
NO_MOCK_REASON,
|
||||
MagicMock,
|
||||
patch
|
||||
)
|
||||
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
|
||||
ensure_in_syspath('../../')
|
||||
|
||||
# Import Salt Libs
|
||||
from salt.states import rabbitmq_plugin
|
||||
|
||||
rabbitmq_plugin.__opts__ = {}
|
||||
rabbitmq_plugin.__salt__ = {}
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class RabbitmqPluginTestCase(TestCase):
|
||||
'''
|
||||
Test cases for salt.states.rabbitmq_plugin
|
||||
'''
|
||||
# 'enabled' function tests: 1
|
||||
|
||||
def test_enabled(self):
|
||||
'''
|
||||
Test to ensure the RabbitMQ plugin is enabled.
|
||||
'''
|
||||
name = 'some_plugin'
|
||||
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': ''}
|
||||
|
||||
mock = MagicMock(side_effect=[True, False])
|
||||
with patch.dict(rabbitmq_plugin.__salt__,
|
||||
{'rabbitmq.plugin_is_enabled': mock}):
|
||||
comt = ('Plugin some_plugin is already enabled')
|
||||
ret.update({'comment': comt})
|
||||
self.assertDictEqual(rabbitmq_plugin.enabled(name), ret)
|
||||
|
||||
with patch.dict(rabbitmq_plugin.__opts__, {'test': True}):
|
||||
comt = ('Plugin some_plugin is set to be enabled')
|
||||
ret.update({'comment': comt, 'result': None})
|
||||
self.assertDictEqual(rabbitmq_plugin.enabled(name), ret)
|
||||
|
||||
# 'disabled' function tests: 1
|
||||
|
||||
def test_disabled(self):
|
||||
'''
|
||||
Test to ensure the RabbitMQ plugin is disabled.
|
||||
'''
|
||||
name = 'some_plugin'
|
||||
|
||||
ret = {'name': name,
|
||||
'changes': {},
|
||||
'result': True,
|
||||
'comment': ''}
|
||||
|
||||
mock = MagicMock(side_effect=[False, True])
|
||||
with patch.dict(rabbitmq_plugin.__salt__,
|
||||
{'rabbitmq.plugin_is_enabled': mock}):
|
||||
comt = ('Plugin some_plugin is not enabled')
|
||||
ret.update({'comment': comt})
|
||||
self.assertDictEqual(rabbitmq_plugin.disabled(name), ret)
|
||||
|
||||
with patch.dict(rabbitmq_plugin.__opts__, {'test': True}):
|
||||
comt = ('Plugin some_plugin is set to be disabled')
|
||||
ret.update({'comment': comt, 'result': None})
|
||||
self.assertDictEqual(rabbitmq_plugin.disabled(name), ret)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
run_tests(RabbitmqPluginTestCase, needs_daemon=False)
|
Loading…
Add table
Reference in a new issue