Add tests for issues #66376 and #41794

This commit is contained in:
jeanluc 2024-05-31 00:30:41 +02:00 committed by Daniel Wozniak
parent 0c8cb6890e
commit 3bcb67f1c1

View file

@ -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"