mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
feat(mac_brew_pkg): Add options to list_upgrades method
This commit is contained in:
parent
cf2b724cbb
commit
8416fe4311
2 changed files with 72 additions and 2 deletions
|
@ -605,20 +605,37 @@ def install(name=None, pkgs=None, taps=None, options=None, **kwargs):
|
|||
return ret
|
||||
|
||||
|
||||
def list_upgrades(refresh=True, include_casks=False, **kwargs): # pylint: disable=W0613
|
||||
def list_upgrades(
|
||||
refresh=True, include_casks=False, options=None, **kwargs
|
||||
): # pylint: disable=W0613
|
||||
"""
|
||||
Check whether or not an upgrade is available for all packages
|
||||
|
||||
refresh
|
||||
Update the Homebrew's package repository before listing upgrades.
|
||||
|
||||
include_casks
|
||||
Whether to include casks in the list of upgrades.
|
||||
|
||||
options
|
||||
Additional options to pass to brew.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' pkg.list_upgrades
|
||||
salt '*' pkg.list_upgrades include_casks=True
|
||||
salt '*' pkg.list_upgrades include_casks=True options='["--greedy"]'
|
||||
"""
|
||||
if refresh:
|
||||
refresh_db()
|
||||
|
||||
res = _call_brew("outdated", "--json=v2")
|
||||
cmd = ["outdated", "--json=v2"]
|
||||
if options:
|
||||
cmd.extend(options)
|
||||
|
||||
res = _call_brew(*cmd)
|
||||
ret = {}
|
||||
|
||||
try:
|
||||
|
|
|
@ -1459,3 +1459,56 @@ def test_list_upgrades(HOMEBREW_BIN):
|
|||
assert (
|
||||
mac_brew.list_upgrades(refresh=False, include_casks=True) == _expected
|
||||
)
|
||||
|
||||
|
||||
def test_list_upgrades_with_options():
|
||||
"""
|
||||
Tests list_upgrades method using options
|
||||
"""
|
||||
mock_call_brew = MagicMock(
|
||||
return_value={
|
||||
"pid": 12345,
|
||||
"retcode": 0,
|
||||
"stderr": "",
|
||||
"stdout": textwrap.dedent(
|
||||
"""\
|
||||
{
|
||||
"formulae": [
|
||||
|
||||
],
|
||||
"casks": [
|
||||
{
|
||||
"name": "1password",
|
||||
"installed_versions": [
|
||||
"8.10.24"
|
||||
],
|
||||
"current_version": "8.10.33"
|
||||
},
|
||||
{
|
||||
"name": "bbedit",
|
||||
"installed_versions": [
|
||||
"15.0.1"
|
||||
],
|
||||
"current_version": "15.1"
|
||||
}
|
||||
]
|
||||
}
|
||||
"""
|
||||
),
|
||||
}
|
||||
)
|
||||
_expected = {
|
||||
"1password": "8.10.33",
|
||||
"bbedit": "15.1",
|
||||
}
|
||||
|
||||
with patch("salt.modules.mac_brew_pkg._call_brew", mock_call_brew):
|
||||
assert (
|
||||
mac_brew.list_upgrades(
|
||||
refresh=False, include_casks=True, options=["--greedy", "--fetch-HEAD"]
|
||||
)
|
||||
== _expected
|
||||
)
|
||||
mock_call_brew.assert_called_once_with(
|
||||
"outdated", "--json=v2", "--greedy", "--fetch-HEAD"
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue