Add test for issue #66600

This commit is contained in:
jeanluc 2024-05-30 21:41:23 +02:00 committed by Daniel Wozniak
parent 44d96002e9
commit 47e4c80a74

View file

@ -28,3 +28,54 @@ def test_echo(salt_ssh_cli, base_env_state_tree_root_dir):
ret = salt_ssh_cli.run("state.apply", name)
result = StateResult(ret.data)
assert result.comment == echo
@pytest.fixture
def _exewrap(base_env_state_tree_root_dir, salt_run_cli):
exe = """
def run():
return "exe"
"""
wrapper = """
def run():
return "wrapper"
"""
name = "exewrap"
try:
with pytest.helpers.temp_file(
f"{name}.py", exe, base_env_state_tree_root_dir / "_modules"
):
with pytest.helpers.temp_file(
f"{name}.py", wrapper, base_env_state_tree_root_dir / "_wrapper"
):
res = salt_run_cli.run("saltutil.sync_all")
assert res.returncode == 0
assert f"modules.{name}" in res.data["modules"]
assert f"wrapper.{name}" in res.data["wrapper"]
yield name
finally:
res = salt_run_cli.run("saltutil.sync_all")
assert res.returncode == 0
@pytest.fixture
def _jinja_loader_attr_template(base_env_state_tree_root_dir, _exewrap):
contents = f"""
foo:
test.show_notification:
- text: {{{{ salt.{_exewrap}.run() | json }}}}
"""
name = "exewrap_test"
with pytest.helpers.temp_file(
f"{name}.sls", contents, base_env_state_tree_root_dir
):
yield name
def test_wrapper_attribute_access(_jinja_loader_attr_template, salt_ssh_cli):
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"