salt/tests/unit/modules/test_munin.py

65 lines
1.9 KiB
Python
Raw Normal View History

2015-02-03 08:47:14 +00:00
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
'''
# Import Python Libs
from __future__ import absolute_import
2015-02-03 08:47:14 +00:00
# Import Salt Testing Libs
2017-02-19 22:28:46 +00:00
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.mock import (
2015-02-03 08:47:14 +00:00
MagicMock,
patch,
NO_MOCK,
NO_MOCK_REASON
)
# Import Salt Libs
2017-02-19 22:28:46 +00:00
import salt.modules.munin as munin
2015-02-03 08:47:14 +00:00
@skipIf(NO_MOCK, NO_MOCK_REASON)
2017-02-19 22:28:46 +00:00
class MuninTestCase(TestCase, LoaderModuleMockMixin):
2015-02-03 08:47:14 +00:00
'''
Test cases for salt.modules.munin
'''
def setup_loader_modules(self):
return {munin: {}}
2015-02-03 08:47:14 +00:00
# 'run' function tests: 1
def test_run(self):
'''
Test if it runs one or more named munin plugins
'''
mock = MagicMock(return_value='uptime.value 0.01')
2017-04-10 13:00:57 +00:00
with patch.dict(munin.__salt__, {'cmd.run': mock}), \
patch('salt.modules.munin.list_plugins',
MagicMock(return_value=['uptime'])):
2015-02-03 08:47:14 +00:00
self.assertDictEqual(munin.run('uptime'),
{'uptime': {'uptime': 0.01}})
# 'run_all' function tests: 1
def test_run_all(self):
'''
Test if it runs all the munin plugins
'''
mock = MagicMock(return_value='uptime.value 0.01')
2017-04-10 13:00:57 +00:00
with patch.dict(munin.__salt__, {'cmd.run': mock}), \
patch('salt.modules.munin.list_plugins',
MagicMock(return_value=['uptime'])):
2015-02-03 08:47:14 +00:00
self.assertDictEqual(munin.run_all(), {'uptime': {'uptime': 0.01}})
# 'list_plugins' function tests: 1
def test_list_plugins(self):
'''
Test if it list all the munin plugins
'''
2017-04-10 13:00:57 +00:00
with patch('salt.modules.munin.list_plugins',
MagicMock(return_value=['uptime'])):
self.assertListEqual(munin.list_plugins(), ['uptime'])