mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
feat(mac_brew_pkg): Add options to remove method
This commit is contained in:
parent
ad6ebb175f
commit
ae69865ab3
2 changed files with 36 additions and 2 deletions
|
@ -356,7 +356,7 @@ available_version = salt.utils.functools.alias_function(
|
|||
)
|
||||
|
||||
|
||||
def remove(name=None, pkgs=None, **kwargs):
|
||||
def remove(name=None, pkgs=None, options=None, **kwargs):
|
||||
"""
|
||||
Removes packages with ``brew uninstall``.
|
||||
|
||||
|
@ -370,6 +370,10 @@ def remove(name=None, pkgs=None, **kwargs):
|
|||
A list of packages to delete. Must be passed as a python list. The
|
||||
``name`` parameter will be ignored if this option is passed.
|
||||
|
||||
options
|
||||
Additional options to pass to brew. Useful to remove ambiguous packages
|
||||
that can conflict between formulae and casks.
|
||||
|
||||
.. versionadded:: 0.16.0
|
||||
|
||||
|
||||
|
@ -382,6 +386,7 @@ def remove(name=None, pkgs=None, **kwargs):
|
|||
salt '*' pkg.remove <package name>
|
||||
salt '*' pkg.remove <package1>,<package2>,<package3>
|
||||
salt '*' pkg.remove pkgs='["foo", "bar"]'
|
||||
salt '*' pkg.remove pkgs='["foo", "bar"]' options='["--cask"]'
|
||||
"""
|
||||
try:
|
||||
pkg_params = __salt__["pkg_resource.parse_targets"](name, pkgs, **kwargs)[0]
|
||||
|
@ -393,7 +398,12 @@ def remove(name=None, pkgs=None, **kwargs):
|
|||
if not targets:
|
||||
return {}
|
||||
|
||||
out = _call_brew("uninstall", *targets)
|
||||
cmd = ["uninstall"]
|
||||
if options:
|
||||
cmd.extend(options)
|
||||
cmd.extend(list(targets))
|
||||
|
||||
out = _call_brew(*cmd)
|
||||
if out["retcode"] != 0 and out["stderr"]:
|
||||
errors = [out["stderr"]]
|
||||
else:
|
||||
|
|
|
@ -994,6 +994,30 @@ def test_remove():
|
|||
assert mac_brew.remove("foo") == {}
|
||||
|
||||
|
||||
def test_remove_with_options():
|
||||
"""
|
||||
Tests if call_brew is called with the expected options
|
||||
"""
|
||||
first_call = True
|
||||
|
||||
def mock_list_pkgs():
|
||||
nonlocal first_call
|
||||
if first_call:
|
||||
first_call = False
|
||||
return {"foo": "0.1.5"}
|
||||
return {}
|
||||
|
||||
mock_params = MagicMock(return_value=({"foo": None}, "repository"))
|
||||
mock_call_brew = MagicMock(return_value={"retcode": 0})
|
||||
with patch("salt.modules.mac_brew_pkg.list_pkgs", mock_list_pkgs), patch(
|
||||
"salt.modules.mac_brew_pkg._call_brew", mock_call_brew
|
||||
), patch.dict(mac_brew.__salt__, {"pkg_resource.parse_targets": mock_params}):
|
||||
assert mac_brew.remove("foo", options=["--cask"]) == {
|
||||
"foo": {"new": "", "old": "0.1.5"}
|
||||
}
|
||||
mock_call_brew.assert_called_once_with("uninstall", "--cask", "foo")
|
||||
|
||||
|
||||
# 'refresh_db' function tests: 2
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue