mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Allow to check whether a function is available on the AliasesLoader wrapper
This commit is contained in:
parent
866a1febb4
commit
915d94219e
3 changed files with 25 additions and 0 deletions
|
@ -82,6 +82,13 @@ class AliasedLoader(object):
|
|||
else:
|
||||
return getattr(self.wrapped, name)
|
||||
|
||||
def __contains__(self, name):
|
||||
if name in ALIASES:
|
||||
salt.utils.warn_until('Nitrogen', ALIAS_WARN)
|
||||
return ALIASES[name] in self.wrapped
|
||||
else:
|
||||
return name in self.wrapped
|
||||
|
||||
|
||||
class AliasedModule(object):
|
||||
'''
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
{% set salt_foo_bar_exist = 'foo.bar' in salt %}
|
||||
{% set salt_test_ping_exist = 'test.ping' in salt %}
|
||||
|
||||
test-ping-exist:
|
||||
test.succeed_without_changes:
|
||||
- name: salt_test_ping_exist_{{ salt_test_ping_exist }}
|
||||
|
||||
foo-bar-not-exist:
|
||||
test.succeed_without_changes:
|
||||
- name: salt_foo_bar_exist_{{ salt_foo_bar_exist }}
|
|
@ -26,6 +26,14 @@ class TestJinjaRenderer(integration.ModuleCase):
|
|||
for state_ret in ret.values():
|
||||
self.assertTrue(state_ret['result'])
|
||||
|
||||
def test_salt_contains_function(self):
|
||||
'''
|
||||
Test if we are able to check if a function exists inside the "salt"
|
||||
wrapper (AliasLoader) which is available on Jinja templates.
|
||||
'''
|
||||
ret = self.run_function('state.sls', ['jinja_salt_contains_function'])
|
||||
for state_ret in ret.values():
|
||||
self.assertTrue(state_ret['result'])
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
|
|
Loading…
Add table
Reference in a new issue