mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Unit test for backwards compatibility of mine.get
Could not find calls to RemoteFuncs in unit tests, therefore started a new one, hope it's in the appropriate place. The test replaces the caceh by its own (very limited) one. It's quite possible it could be improved by reusing another one meant for unit tests.
This commit is contained in:
parent
40a2759ff4
commit
728c9b65a5
@ -199,3 +199,59 @@ class LocalFuncsTestCase(TestCase):
|
||||
u'user UNKNOWN.'}}
|
||||
ret = self.local_funcs.wheel({})
|
||||
self.assertDictEqual(mock_ret, ret)
|
||||
|
||||
|
||||
class FakeCache(object):
|
||||
|
||||
def __init__(self):
|
||||
self.data = {}
|
||||
|
||||
def store(self, bank, key, value):
|
||||
self.data[bank, key] = value
|
||||
|
||||
def fetch(self, bank, key):
|
||||
return self.data[bank, key]
|
||||
|
||||
|
||||
class RemoteFuncsTestCase(TestCase):
|
||||
'''
|
||||
TestCase for salt.daemons.masterapi.RemoteFuncs class
|
||||
'''
|
||||
|
||||
def setUp(self):
|
||||
opts = salt.config.master_config(None)
|
||||
self.funcs = masterapi.RemoteFuncs(opts)
|
||||
self.funcs.cache = FakeCache()
|
||||
|
||||
def test_mine_get(self, tgt_type_key='tgt_type'):
|
||||
'''
|
||||
Asserts that ``mine_get`` gives the expected results.
|
||||
|
||||
Actually this only tests that:
|
||||
|
||||
- the correct check minions method is called
|
||||
- the correct cache key is subsequently used
|
||||
'''
|
||||
self.funcs.cache.store('minions/webserver', 'mine',
|
||||
dict(ip_addr='2001:db8::1:3'))
|
||||
with patch('salt.utils.minions.CkMinions._check_compound_minions',
|
||||
MagicMock(return_value=(dict(
|
||||
minions=['webserver'],
|
||||
missing=[])))):
|
||||
ret = self.funcs._mine_get(
|
||||
{
|
||||
'id': 'requester_minion',
|
||||
'tgt': 'G@roles:web',
|
||||
'fun': 'ip_addr',
|
||||
tgt_type_key: 'compound',
|
||||
}
|
||||
)
|
||||
self.assertDictEqual(ret, dict(webserver='2001:db8::1:3'))
|
||||
|
||||
def test_mine_get_pre_nitrogen_compat(self):
|
||||
'''
|
||||
Asserts that pre-Nitrogen API key ``expr_form`` is still accepted.
|
||||
|
||||
This is what minions before Nitrogen would issue.
|
||||
'''
|
||||
self.test_mine_get(tgt_type_key='expr_form')
|
||||
|
Loading…
Reference in New Issue
Block a user