diff --git a/changelog/64150.fixed.md b/changelog/64150.fixed.md new file mode 100644 index 000000000000..a767e10bf8db --- /dev/null +++ b/changelog/64150.fixed.md @@ -0,0 +1 @@ +Fix cmd.run doesn't output changes in test mode diff --git a/salt/states/cmd.py b/salt/states/cmd.py index 2df04807ce33..5a859c8092c6 100644 --- a/salt/states/cmd.py +++ b/salt/states/cmd.py @@ -849,6 +849,7 @@ def run( if __opts__["test"] and not test_name: ret["result"] = None ret["comment"] = 'Command "{}" would have been executed'.format(name) + ret["changes"] = {"cmd": name} return _reinterpreted_state(ret) if stateful else ret if cwd and not os.path.isdir(cwd): diff --git a/tests/pytests/unit/states/test_cmd.py b/tests/pytests/unit/states/test_cmd.py index 682ee621e7d4..4a839c2f91ac 100644 --- a/tests/pytests/unit/states/test_cmd.py +++ b/tests/pytests/unit/states/test_cmd.py @@ -77,7 +77,9 @@ def test_run(): with patch.dict(cmd.__opts__, {"test": True}): comt = 'Command "cmd.script" would have been executed' - ret.update({"comment": comt, "result": None, "changes": {}}) + ret.update( + {"comment": comt, "result": None, "changes": {"cmd": "cmd.script"}} + ) assert cmd.run(name) == ret