mirror of
https://github.com/valitydev/salt.git
synced 2024-11-06 16:45:27 +00:00
Merge pull request #53584 from dwoz/client_cache
Add unit tests for recent SaltCacheLoader changes
This commit is contained in:
commit
77b7fc46b5
@ -62,7 +62,9 @@ class SaltCacheLoader(BaseLoader):
|
||||
def shutdown(cls):
|
||||
if cls._cached_client is None:
|
||||
return
|
||||
cls._cached_client.destroy()
|
||||
# PillarClient and LocalClient objects do not have a destroy method
|
||||
if hasattr(cls._cached_client, 'destroy'):
|
||||
cls._cached_client.destroy()
|
||||
cls._cached_client = None
|
||||
|
||||
def __init__(self, opts, saltenv='base', encoding='utf-8',
|
||||
|
@ -122,7 +122,10 @@ class TestSaltCacheLoader(TestCase):
|
||||
},
|
||||
'pillar_roots': {
|
||||
'test': [self.template_dir]
|
||||
}
|
||||
},
|
||||
'extension_modules': os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
'extmods'),
|
||||
}
|
||||
super(TestSaltCacheLoader, self).setUp()
|
||||
|
||||
@ -223,6 +226,36 @@ class TestSaltCacheLoader(TestCase):
|
||||
result = jinja.get_template('hello_include').render(a='Hi', b='Salt')
|
||||
self.assertEqual(result, 'Hey world !Hi Salt !')
|
||||
|
||||
def test_cached_file_client(self):
|
||||
'''
|
||||
Multiple instantiations of SaltCacheLoader use the cached file client
|
||||
'''
|
||||
with patch('salt.transport.client.ReqChannel.factory', Mock()):
|
||||
loader_a = SaltCacheLoader(self.opts)
|
||||
loader_b = SaltCacheLoader(self.opts)
|
||||
assert loader_a._file_client is loader_b._file_client
|
||||
|
||||
def test_file_client_kwarg(self):
|
||||
'''
|
||||
A file client can be passed to SaltCacheLoader overriding the any
|
||||
cached file client
|
||||
'''
|
||||
mfc = MockFileClient()
|
||||
loader = SaltCacheLoader(self.opts, _file_client=mfc)
|
||||
assert loader._file_client is mfc
|
||||
|
||||
def test_cache_loader_shutdown(self):
|
||||
'''
|
||||
The shudown method can be called without raising an exception when the
|
||||
file_client does not have a destroy method
|
||||
'''
|
||||
mfc = MockFileClient()
|
||||
assert not hasattr(mfc, 'destroy')
|
||||
loader = SaltCacheLoader(self.opts, _file_client=mfc)
|
||||
assert loader._file_client is mfc
|
||||
# Shutdown method should not raise any exceptions
|
||||
loader.shutdown()
|
||||
|
||||
|
||||
class TestGetTemplate(TestCase):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user