Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test output for running services #60150

Merged
merged 1 commit into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions salt/states/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,19 @@ def running(name, enable=None, sig=None, init_delay=None, **kwargs):
ret.update(_enable(name, None, **kwargs))
elif enable is False and before_toggle_enable_status:
ret.update(_disable(name, None, **kwargs))
else:
if __opts__["test"]:
ret["result"] = None
ret["comment"] = "\n".join(
[
_f
for _f in [
"The service {} is set to restart".format(name),
unmask_ret["comment"],
]
if _f
]
)
return ret

# Run the tests
Expand Down
8 changes: 7 additions & 1 deletion tests/pytests/unit/states/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ def test_running():
"name": "salt",
"result": False,
},
{
"changes": {},
"comment": "The service salt is set to restart",
"name": "salt",
"result": None,
},
]

tmock = MagicMock(return_value=True)
Expand Down Expand Up @@ -231,7 +237,7 @@ def test_running():

with patch.dict(service.__opts__, {"test": True}):
with patch.dict(service.__salt__, {"service.status": tmock}):
assert service.running("salt") == ret[5]
assert service.running("salt") == ret[10]

with patch.dict(service.__salt__, {"service.status": fmock}):
assert service.running("salt") == ret[3]
Expand Down