adding logrotate unit test

This commit is contained in:
Jayesh Kariya 2015-02-03 13:59:01 +05:30
parent d1c0e067e5
commit ec88812ed9

View File

@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Jayesh Kariya <jayeshk@saltstack.com>`
'''
# Import Salt Testing Libs
from salttesting import TestCase, skipIf
from salttesting.mock import (
MagicMock,
patch,
NO_MOCK,
NO_MOCK_REASON
)
# Import Salt Libs
from salt.modules import logrotate
# Globals
logrotate.__salt__ = {}
@skipIf(NO_MOCK, NO_MOCK_REASON)
class LogrotateTestCase(TestCase):
'''
Test cases for salt.modules.logrotate
'''
# 'show_conf' function tests: 1
@patch('salt.modules.logrotate._parse_conf',
MagicMock(return_value=True))
def test_show_conf(self):
'''
Test if it show parsed configuration
'''
self.assertTrue(logrotate.show_conf())
# 'set_' function tests: 2
@patch('salt.modules.logrotate._parse_conf',
MagicMock(return_value={'include files': {'include':'A'},
'rotate': {'salt':'A'}}))
def test_set(self):
'''
Test if it set a new value for a specific configuration line
'''
ret = (
'Error: rotate includes a dict, and a specific '
'setting inside the dict was not declared'
)
self.assertEqual(logrotate.set_('rotate', '2'), ret)
@patch('salt.modules.logrotate._parse_conf',
MagicMock(return_value={'include files': {'include':'A'},
'rotate': 'salt'}))
def test_set_setting(self):
'''
Test if it set a new value for a specific configuration line
'''
ret = (
'Error: A setting for a dict was declared, '
'but the configuration line given is not a dict'
)
self.assertEqual(logrotate.set_('rotate', '2', True), ret)
if __name__ == '__main__':
from integration import run_tests
run_tests(LogrotateTestCase, needs_daemon=False)