mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add test for issue #66996
This commit is contained in:
parent
ed89424059
commit
931e4632ce
1 changed files with 45 additions and 0 deletions
|
@ -3,6 +3,7 @@ import os
|
|||
import textwrap
|
||||
import threading
|
||||
import time
|
||||
from textwrap import dedent
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -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
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue