Skip to content

Commit

Permalink
Add test for issue saltstack#66996
Browse files Browse the repository at this point in the history
  • Loading branch information
lkubb committed Oct 24, 2024
1 parent eee8215 commit 8457d9b
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/pytests/functional/modules/state/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import textwrap
import threading
import time
from textwrap import dedent

import pytest

Expand Down Expand Up @@ -1081,3 +1082,47 @@ def test_state_sls_mock_ret(state_tree):
ret["cmd_|-echo1_|-echo 'This is a test!'_|-run"]["comment"]
== "Not called, mocked"
)


@pytest.fixture
def _state_requires_env(loaders, state_tree):
mod_contents = dedent(
r"""
def test_it(name):
return {
"name": name,
"result": __env__ == "base",
"comment": "",
"changes": {},
}
"""
)
sls = "test_spawning"
sls_contents = dedent(
"""
This should not fail on spawning platforms:
requires_env.test_it:
- name: foo
- parallel: true
"""
)
with pytest.helpers.temp_file(
f"{sls}.sls", sls_contents, state_tree
), pytest.helpers.temp_file("_states/requires_env.py", mod_contents, state_tree):
res = loaders.modules.saltutil.sync_states()
assert "states.requires_env" in res
yield sls


def test_state_apply_parallel_spawning_with_global_dunders(state, _state_requires_env):
"""
Ensure state modules called via `parallel: true` have access to injected
global dunders like `__env__`.
"""
ret = state.apply(_state_requires_env)
assert (
ret[
"requires_env_|-This should not fail on spawning platforms_|-foo_|-test_it"
]["result"]
is True
)

0 comments on commit 8457d9b

Please sign in to comment.