mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
cache runner test: add new unit tests
This commit is contained in:
parent
1e9214f4e4
commit
0c0bce3ea6
2 changed files with 63 additions and 0 deletions
1
tests/unit/runners/__init__.py
Normal file
1
tests/unit/runners/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
# -*- coding: utf-8 -*-
|
62
tests/unit/runners/cache_test.py
Normal file
62
tests/unit/runners/cache_test.py
Normal file
|
@ -0,0 +1,62 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
unit tests for the cache runner
|
||||
'''
|
||||
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from salttesting import skipIf, TestCase
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
from salttesting.mock import (
|
||||
NO_MOCK,
|
||||
NO_MOCK_REASON,
|
||||
patch
|
||||
)
|
||||
|
||||
ensure_in_syspath('../../')
|
||||
|
||||
# Import Salt Libs
|
||||
from salt.runners import cache
|
||||
import salt.utils
|
||||
|
||||
cache.__opts__ = {}
|
||||
cache.__salt__ = {}
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class CacheTest(TestCase):
|
||||
'''
|
||||
Validate the cache runner
|
||||
'''
|
||||
def test_grains(self):
|
||||
'''
|
||||
test cache.grains runner
|
||||
'''
|
||||
mock_minion = ['Larry']
|
||||
mock_ret = {}
|
||||
self.assertEqual(cache.grains(minion=mock_minion), mock_ret)
|
||||
|
||||
mock_data = 'grain stuff'
|
||||
mock_outputter = 'deprecated'
|
||||
|
||||
class MockMaster(object):
|
||||
def __init__(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def get_minion_grains(self):
|
||||
return mock_data
|
||||
|
||||
mock_ret = {'outputter': mock_outputter, 'data': mock_data}
|
||||
with patch.object(salt.utils.master, 'MasterPillarUtil', MockMaster):
|
||||
self.assertEqual(cache.grains(outputter=mock_outputter), mock_ret)
|
||||
|
||||
mock_outputter = None
|
||||
with patch.object(salt.utils.master, 'MasterPillarUtil', MockMaster):
|
||||
self.assertEqual(cache.grains(outputter=mock_outputter), mock_data)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
run_tests(CacheTest, needs_daemon=False)
|
Loading…
Add table
Reference in a new issue