mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
parent
0c8cb6890e
commit
3bcb67f1c1
1 changed files with 71 additions and 1 deletions
|
@ -66,7 +66,7 @@ foo:
|
|||
test.show_notification:
|
||||
- text: {{{{ salt.{_exewrap}.run() | json }}}}
|
||||
"""
|
||||
name = "exewrap_test"
|
||||
name = "funcwrapper_attr_exewrap_test"
|
||||
with pytest.helpers.temp_file(
|
||||
f"{name}.sls", contents, base_env_state_tree_root_dir
|
||||
):
|
||||
|
@ -74,8 +74,78 @@ foo:
|
|||
|
||||
|
||||
def test_wrapper_attribute_access(_jinja_loader_attr_template, salt_ssh_cli):
|
||||
"""
|
||||
Ensure wrappers can be accessed via the attribute syntax.
|
||||
It's not recommended to use this syntax, but the regular loader supports it
|
||||
as well, so we should have feature parity.
|
||||
Issue #66600.
|
||||
"""
|
||||
res = salt_ssh_cli.run("state.apply", _jinja_loader_attr_template)
|
||||
assert res.returncode == 0
|
||||
ret = StateResult(res.data)
|
||||
assert ret.result is True
|
||||
assert ret.comment == "wrapper"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def _jinja_loader_get_template(base_env_state_tree_root_dir, _exewrap):
|
||||
contents = """
|
||||
foo:
|
||||
test.show_notification:
|
||||
- text: {{ salt.grains.get("id") | json }}
|
||||
"""
|
||||
name = "funcwrapper_attr_get_test"
|
||||
with pytest.helpers.temp_file(
|
||||
f"{name}.sls", contents, base_env_state_tree_root_dir
|
||||
):
|
||||
yield name
|
||||
|
||||
|
||||
def test_wrapper_attribute_access_get(_jinja_loader_get_template, salt_ssh_cli):
|
||||
"""
|
||||
Ensure a function named `.get` is not shadowed when accessed via attribute syntax.
|
||||
It's not recommended to use this syntax, but the regular loader supports it
|
||||
as well, so we should have feature parity.
|
||||
Issue #41794.
|
||||
"""
|
||||
res = salt_ssh_cli.run("state.apply", _jinja_loader_get_template)
|
||||
assert res.returncode == 0
|
||||
ret = StateResult(res.data)
|
||||
assert ret.result is True
|
||||
assert ret.comment == "localhost"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def _python_loader_attribute_access_template(base_env_state_tree_root_dir, _exewrap):
|
||||
contents = """
|
||||
#!py
|
||||
def run():
|
||||
return {
|
||||
"foo": {
|
||||
"test.show_notification": [
|
||||
{"text": __salt__.grains.get("id")}
|
||||
]
|
||||
}
|
||||
}
|
||||
"""
|
||||
name = "funcwrapper_attr_python_test"
|
||||
with pytest.helpers.temp_file(
|
||||
f"{name}.sls", contents, base_env_state_tree_root_dir
|
||||
):
|
||||
yield name
|
||||
|
||||
|
||||
def test_wrapper_attribute_access_non_jinja(
|
||||
_python_loader_attribute_access_template, salt_ssh_cli
|
||||
):
|
||||
"""
|
||||
Ensure attribute access works with non-Jinja renderers.
|
||||
It's not recommended to use this syntax, but the regular loader supports it
|
||||
as well, so we should have feature parity.
|
||||
Issue #66376.
|
||||
"""
|
||||
res = salt_ssh_cli.run("state.apply", _python_loader_attribute_access_template)
|
||||
assert res.returncode == 0
|
||||
ret = StateResult(res.data)
|
||||
assert ret.result is True
|
||||
assert ret.comment == "localhost"
|
||||
|
|
Loading…
Add table
Reference in a new issue