mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add functional tests for 1.2.1 and latest
This commit is contained in:
parent
aea4ce188f
commit
866175b707
7 changed files with 449 additions and 217 deletions
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
A dead simple module wrapping calls to the Chocolatey package manager
|
||||
A module that wraps calls to the Chocolatey package manager
|
||||
(http://chocolatey.org)
|
||||
|
||||
.. versionadded:: 2014.1.0
|
||||
|
@ -40,13 +40,10 @@ def __virtual__():
|
|||
salt-minion running as SYSTEM.
|
||||
"""
|
||||
if not salt.utils.platform.is_windows():
|
||||
return (False, "Cannot load module chocolatey: Chocolatey requires Windows")
|
||||
return False, "Chocolatey: Requires Windows"
|
||||
|
||||
if __grains__["osrelease"] in ("XP", "2003Server"):
|
||||
return (
|
||||
False,
|
||||
"Cannot load module chocolatey: Chocolatey requires Windows Vista or later",
|
||||
)
|
||||
return False, "Chocolatey: Requires Windows Vista or later"
|
||||
|
||||
return __virtualname__
|
||||
|
||||
|
@ -355,12 +352,12 @@ def unbootstrap():
|
|||
"""
|
||||
Uninstall chocolatey from the system by doing the following:
|
||||
|
||||
.. versionadded:: 3001
|
||||
|
||||
- Delete the Chocolatey Directory
|
||||
- Remove Chocolatey from the path
|
||||
- Remove Chocolatey environment variables
|
||||
|
||||
.. versionadded:: 3001
|
||||
|
||||
Returns:
|
||||
list: A list of items that were removed, otherwise an empty list
|
||||
|
||||
|
@ -441,10 +438,10 @@ def list_(
|
|||
None is passed. Default is None.
|
||||
|
||||
local_only (bool):
|
||||
Display packages only installed locally. Default is False.
|
||||
Only display packages that are installed locally. Default is False.
|
||||
|
||||
exact (bool):
|
||||
Display only packages that match ``narrow`` exactly. Default is
|
||||
Only display packages that match ``narrow`` exactly. Default is
|
||||
False.
|
||||
|
||||
.. versionadded:: 2017.7.0
|
||||
|
@ -463,8 +460,14 @@ def list_(
|
|||
# https://docs.chocolatey.org/en-us/guides/upgrading-to-chocolatey-v2-v6
|
||||
if Version(chocolatey_version()) < Version("2.0.0"):
|
||||
cmd = [choc_path, "list"]
|
||||
if local_only:
|
||||
cmd.append("--local-only")
|
||||
else:
|
||||
cmd = [choc_path, "search"]
|
||||
if local_only:
|
||||
# Starting with 2.0.0, list only returns local packages
|
||||
cmd = [choc_path, "list"]
|
||||
else:
|
||||
cmd = [choc_path, "search"]
|
||||
if narrow:
|
||||
cmd.append(narrow)
|
||||
if salt.utils.data.is_true(all_versions):
|
||||
|
@ -473,8 +476,6 @@ def list_(
|
|||
cmd.append("--prerelease")
|
||||
if source:
|
||||
cmd.extend(["--source", source])
|
||||
if local_only:
|
||||
cmd.append("--local-only")
|
||||
if exact:
|
||||
cmd.append("--exact")
|
||||
|
||||
|
@ -589,12 +590,12 @@ def install(
|
|||
|
||||
version (str):
|
||||
Install a specific version of the package. Defaults to latest
|
||||
version. Default is None.
|
||||
version. Default is ``None``.
|
||||
|
||||
source (str):
|
||||
Chocolatey repository (directory, share or remote URL feed) the
|
||||
package comes from. Defaults to the official Chocolatey feed.
|
||||
Default is None.
|
||||
Default is ``None``.
|
||||
|
||||
Alternate Sources:
|
||||
|
||||
|
@ -606,36 +607,38 @@ def install(
|
|||
|
||||
force (bool):
|
||||
Reinstall the current version of an existing package. Do not use
|
||||
with ``allow_multiple``. Default is False.
|
||||
with ``allow_multiple``. Default is ``False``.
|
||||
|
||||
pre_versions (bool):
|
||||
Include pre-release packages. Default is False.
|
||||
Include pre-release packages. Default is ``False``.
|
||||
|
||||
install_args (str):
|
||||
A list of install arguments you want to pass to the installation
|
||||
process i.e product key or feature list. Default is None.
|
||||
process, i.e. product key or feature list. Default is ``None``.
|
||||
|
||||
override_args (bool):
|
||||
Set to true if you want to override the original install arguments
|
||||
(for the native installer) in the package and use your own. When
|
||||
this is set to False install_args will be appended to the end of the
|
||||
default arguments. Default is None.
|
||||
this is set to ``False`` install_args will be appended to the end of
|
||||
the default arguments. Default is ``None``.
|
||||
|
||||
force_x86 (bool):
|
||||
Force x86 (32bit) installation on 64 bit systems. Default is False.
|
||||
Force x86 (32bit) installation on 64bit systems. Default is
|
||||
``False``.
|
||||
|
||||
package_args (str):
|
||||
Arguments you want to pass to the package. Default is None.
|
||||
Arguments you want to pass to the package. Default is ``None``.
|
||||
|
||||
allow_multiple (bool):
|
||||
Allow multiple versions of the package to be installed. Do not use
|
||||
with ``force``. Does not work with all packages. Default is False.
|
||||
with ``force``. Does not work with all packages. Default is
|
||||
``False``.
|
||||
|
||||
.. versionadded:: 2017.7.0
|
||||
|
||||
execution_timeout (str):
|
||||
Chocolatey execution timeout value you want to pass to the
|
||||
installation process. Default is None.
|
||||
installation process. Default is ``None``.
|
||||
|
||||
.. versionadded:: 2018.3.0
|
||||
|
||||
|
@ -700,18 +703,21 @@ def install_cygwin(name, install_args=None, override_args=False):
|
|||
"""
|
||||
Instructs Chocolatey to install a package via Cygwin.
|
||||
|
||||
name
|
||||
The name of the package to be installed. Only accepts a single argument.
|
||||
Args:
|
||||
|
||||
install_args
|
||||
A list of install arguments you want to pass to the installation process
|
||||
i.e product key or feature list
|
||||
name (str):
|
||||
The name of the package to be installed. Only accepts a single
|
||||
argument.
|
||||
|
||||
override_args
|
||||
Set to true if you want to override the original install arguments (for
|
||||
the native installer) in the package and use your own. When this is set
|
||||
to False install_args will be appended to the end of the default
|
||||
arguments
|
||||
install_args (str):
|
||||
A list of install arguments you want to pass to the installation
|
||||
process, i.e. product key or feature list
|
||||
|
||||
override_args (bool):
|
||||
Set to ``True`` if you want to override the original install
|
||||
arguments (for the native installer) in the package and use your
|
||||
own. When this is set to ``False`` install_args will be appended to
|
||||
the end of the default arguments
|
||||
|
||||
CLI Example:
|
||||
|
||||
|
@ -729,22 +735,25 @@ def install_gem(name, version=None, install_args=None, override_args=False):
|
|||
"""
|
||||
Instructs Chocolatey to install a package via Ruby's Gems.
|
||||
|
||||
name
|
||||
The name of the package to be installed. Only accepts a single argument.
|
||||
Args:
|
||||
|
||||
version
|
||||
Install a specific version of the package. Defaults to latest version
|
||||
available.
|
||||
name (str):
|
||||
The name of the package to be installed. Only accepts a single
|
||||
argument.
|
||||
|
||||
install_args
|
||||
A list of install arguments you want to pass to the installation process
|
||||
i.e product key or feature list
|
||||
version (str):
|
||||
Install a specific version of the package. Defaults to the latest
|
||||
version available.
|
||||
|
||||
override_args
|
||||
Set to true if you want to override the original install arguments (for
|
||||
the native installer) in the package and use your own. When this is set
|
||||
to False install_args will be appended to the end of the default
|
||||
arguments
|
||||
install_args (str):
|
||||
A list of install arguments you want to pass to the installation
|
||||
process, i.e. product key or feature list
|
||||
|
||||
override_args (bool):
|
||||
Set to ``True`` if you want to override the original install
|
||||
arguments (for the native installer) in the package and use your
|
||||
own. When this is set to ``False`` install_args will be appended to
|
||||
the end of the default arguments
|
||||
|
||||
CLI Example:
|
||||
|
||||
|
@ -773,16 +782,19 @@ def install_missing(name, version=None, source=None):
|
|||
``installmissing`` is deprecated as of that version and will be removed
|
||||
in Chocolatey 1.0.
|
||||
|
||||
name
|
||||
The name of the package to be installed. Only accepts a single argument.
|
||||
Args:
|
||||
|
||||
version
|
||||
Install a specific version of the package. Defaults to latest version
|
||||
available.
|
||||
name (str):
|
||||
The name of the package to be installed. Only accepts a single
|
||||
argument.
|
||||
|
||||
source
|
||||
Chocolatey repository (directory, share or remote URL feed) the package
|
||||
comes from. Defaults to the official Chocolatey feed.
|
||||
version (str):
|
||||
Install a specific version of the package. Defaults to the latest
|
||||
version available.
|
||||
|
||||
source (str):
|
||||
Chocolatey repository (directory, share or remote URL feed) the
|
||||
package comes from. Defaults to the official Chocolatey feed.
|
||||
|
||||
CLI Example:
|
||||
|
||||
|
@ -816,22 +828,25 @@ def install_python(name, version=None, install_args=None, override_args=False):
|
|||
"""
|
||||
Instructs Chocolatey to install a package via Python's easy_install.
|
||||
|
||||
name
|
||||
The name of the package to be installed. Only accepts a single argument.
|
||||
Args:
|
||||
|
||||
version
|
||||
Install a specific version of the package. Defaults to latest version
|
||||
available.
|
||||
name (str):
|
||||
The name of the package to be installed. Only accepts a single
|
||||
argument.
|
||||
|
||||
install_args
|
||||
A list of install arguments you want to pass to the installation process
|
||||
i.e product key or feature list
|
||||
version (str):
|
||||
Install a specific version of the package. Defaults to the latest
|
||||
version available.
|
||||
|
||||
override_args
|
||||
Set to true if you want to override the original install arguments (for
|
||||
the native installer) in the package and use your own. When this is set
|
||||
to False install_args will be appended to the end of the default
|
||||
arguments
|
||||
install_args (str):
|
||||
A list of install arguments you want to pass to the installation
|
||||
process, i.e. product key or feature list.
|
||||
|
||||
override_args (bool):
|
||||
Set to ``True`` if you want to override the original install
|
||||
arguments (for the native installer) in the package and use your
|
||||
own. When this is set to ``False`` install_args will be appended to
|
||||
the end of the default arguments.
|
||||
|
||||
CLI Example:
|
||||
|
||||
|
@ -855,8 +870,11 @@ def install_windowsfeatures(name):
|
|||
Instructs Chocolatey to install a Windows Feature via the Deployment Image
|
||||
Servicing and Management tool.
|
||||
|
||||
name
|
||||
The name of the feature to be installed. Only accepts a single argument.
|
||||
Args:
|
||||
|
||||
name (str):
|
||||
The name of the feature to be installed. Only accepts a single
|
||||
argument.
|
||||
|
||||
CLI Example:
|
||||
|
||||
|
@ -871,18 +889,21 @@ def install_webpi(name, install_args=None, override_args=False):
|
|||
"""
|
||||
Instructs Chocolatey to install a package via the Microsoft Web PI service.
|
||||
|
||||
name
|
||||
The name of the package to be installed. Only accepts a single argument.
|
||||
Args:
|
||||
|
||||
install_args
|
||||
A list of install arguments you want to pass to the installation process
|
||||
i.e product key or feature list
|
||||
name (str):
|
||||
The name of the package to be installed. Only accepts a single
|
||||
argument.
|
||||
|
||||
override_args
|
||||
Set to true if you want to override the original install arguments (for
|
||||
the native installer) in the package and use your own. When this is set
|
||||
to False install_args will be appended to the end of the default
|
||||
arguments
|
||||
install_args (str):
|
||||
A list of install arguments you want to pass to the installation
|
||||
process, i.e. product key or feature list.
|
||||
|
||||
override_args (bool):
|
||||
Set to ``True`` if you want to override the original install
|
||||
arguments (for the native installer) in the package and use your
|
||||
own. When this is set to ``False`` install_args will be appended to
|
||||
the end of the default arguments.
|
||||
|
||||
CLI Example:
|
||||
|
||||
|
@ -906,23 +927,25 @@ def uninstall(
|
|||
"""
|
||||
Instructs Chocolatey to uninstall a package.
|
||||
|
||||
name
|
||||
The name of the package to be uninstalled. Only accepts a single
|
||||
argument.
|
||||
Args:
|
||||
|
||||
version
|
||||
Uninstalls a specific version of the package. Defaults to latest version
|
||||
installed.
|
||||
name (str):
|
||||
The name of the package to be uninstalled. Only accepts a single
|
||||
argument.
|
||||
|
||||
uninstall_args
|
||||
A list of uninstall arguments you want to pass to the uninstallation
|
||||
process i.e product key or feature list
|
||||
version (str):
|
||||
Uninstalls a specific version of the package. Defaults to the latest
|
||||
version installed.
|
||||
|
||||
override_args
|
||||
Set to true if you want to override the original uninstall arguments
|
||||
(for the native uninstaller) in the package and use your own. When this
|
||||
is set to False uninstall_args will be appended to the end of the
|
||||
default arguments
|
||||
uninstall_args (str):
|
||||
A list of uninstall arguments you want to pass to the uninstallation
|
||||
process, i.e. product key or feature list.
|
||||
|
||||
override_args
|
||||
Set to ``True`` if you want to override the original uninstall
|
||||
arguments (for the native uninstaller) in the package and use your
|
||||
own. When this is set to ``False`` uninstall_args will be appended
|
||||
to the end of the default arguments.
|
||||
|
||||
CLI Example:
|
||||
|
||||
|
@ -984,26 +1007,27 @@ def upgrade(
|
|||
package comes from. Defaults to the official Chocolatey feed.
|
||||
|
||||
force (bool):
|
||||
Reinstall the **same** version already installed
|
||||
Reinstall the **same** version already installed.
|
||||
|
||||
pre_versions (bool):
|
||||
Include pre-release packages in comparison. Defaults to False.
|
||||
Include pre-release packages in comparison. Defaults to ``False``.
|
||||
|
||||
install_args (str):
|
||||
A list of install arguments you want to pass to the installation
|
||||
process i.e product key or feature list
|
||||
process, i.e. product key or feature list.
|
||||
|
||||
override_args (str):
|
||||
Set to true if you want to override the original install arguments
|
||||
(for the native installer) in the package and use your own. When
|
||||
this is set to False install_args will be appended to the end of the
|
||||
default arguments
|
||||
override_args (bool):
|
||||
Set to ``True`` if you want to override the original install
|
||||
arguments (for the native installer) in the package and use your
|
||||
own. When this is set to ``False`` install_args will be appended to
|
||||
the end of the default arguments.
|
||||
|
||||
force_x86
|
||||
Force x86 (32bit) installation on 64 bit systems. Defaults to false.
|
||||
force_x86 (bool):
|
||||
Force x86 (32bit) installation on 64bit systems. Defaults to
|
||||
``False``.
|
||||
|
||||
package_args
|
||||
A list of arguments you want to pass to the package
|
||||
package_args (str):
|
||||
A list of arguments you want to pass to the package.
|
||||
|
||||
Returns:
|
||||
str: Results of the ``chocolatey`` command
|
||||
|
@ -1051,16 +1075,18 @@ def update(name, source=None, pre_versions=False):
|
|||
"""
|
||||
Instructs Chocolatey to update packages on the system.
|
||||
|
||||
name
|
||||
The name of the package to update, or "all" to update everything
|
||||
installed on the system.
|
||||
Args:
|
||||
|
||||
source
|
||||
Chocolatey repository (directory, share or remote URL feed) the package
|
||||
comes from. Defaults to the official Chocolatey feed.
|
||||
name (str):
|
||||
The name of the package to update, or "all" to update everything
|
||||
installed on the system.
|
||||
|
||||
pre_versions
|
||||
Include pre-release packages in comparison. Defaults to False.
|
||||
source (str):
|
||||
Chocolatey repository (directory, share or remote URL feed) the
|
||||
package comes from. Defaults to the official Chocolatey feed.
|
||||
|
||||
pre_versions (bool):
|
||||
Include pre-release packages in comparison. Defaults to ``False``.
|
||||
|
||||
CLI Example:
|
||||
|
||||
|
@ -1104,15 +1130,15 @@ def version(name, check_remote=False, source=None, pre_versions=False):
|
|||
|
||||
check_remote (bool):
|
||||
Get the version number of the latest package from the remote feed.
|
||||
Default is False.
|
||||
Default is ``False``.
|
||||
|
||||
source (str):
|
||||
Chocolatey repository (directory, share or remote URL feed) the
|
||||
package comes from. Defaults to the official Chocolatey feed.
|
||||
Default is None.
|
||||
Default is ``None``.
|
||||
|
||||
pre_versions (bool):
|
||||
Include pre-release packages in comparison. Default is False.
|
||||
Include pre-release packages in comparison. Default is ``False``.
|
||||
|
||||
Returns:
|
||||
dict: A dictionary of currently installed software and versions
|
||||
|
@ -1137,7 +1163,9 @@ def version(name, check_remote=False, source=None, pre_versions=False):
|
|||
if check_remote:
|
||||
# If there's a remote package available, then also include that
|
||||
# in the dictionary that we return.
|
||||
available = list_(narrow=name, local_only=False, pre_versions=pre_versions, source=source)
|
||||
available = list_(
|
||||
narrow=name, local_only=False, pre_versions=pre_versions, source=source
|
||||
)
|
||||
if available:
|
||||
for pkg in available:
|
||||
if lower_name == pkg.lower():
|
||||
|
@ -1151,25 +1179,27 @@ def add_source(name, source_location, username=None, password=None, priority=Non
|
|||
"""
|
||||
Instructs Chocolatey to add a source.
|
||||
|
||||
name
|
||||
The name of the source to be added as a chocolatey repository.
|
||||
Args:
|
||||
|
||||
source
|
||||
Location of the source you want to work with.
|
||||
name (str):
|
||||
The name of the source to be added as a chocolatey repository.
|
||||
|
||||
username
|
||||
Provide username for chocolatey sources that need authentication
|
||||
credentials.
|
||||
source (str):
|
||||
Location of the source you want to work with.
|
||||
|
||||
password
|
||||
Provide password for chocolatey sources that need authentication
|
||||
credentials.
|
||||
username (str):
|
||||
Provide username for chocolatey sources that need authentication
|
||||
credentials.
|
||||
|
||||
priority
|
||||
The priority order of this source as compared to other sources,
|
||||
lower is better. Defaults to 0 (no priority). All priorities
|
||||
above 0 will be evaluated first, then zero-based values will be
|
||||
evaluated in config file order.
|
||||
password (str):
|
||||
Provide password for chocolatey sources that need authentication
|
||||
credentials.
|
||||
|
||||
priority (int):
|
||||
The priority order of this source as compared to other sources,
|
||||
lower is better. Defaults to 0 (no priority). All priorities
|
||||
above 0 will be evaluated first, then zero-based values will be
|
||||
evaluated in config file order.
|
||||
|
||||
CLI Example:
|
||||
|
||||
|
@ -1208,12 +1238,13 @@ def _change_source_state(name, state):
|
|||
"""
|
||||
Instructs Chocolatey to change the state of a source.
|
||||
|
||||
name
|
||||
Name of the repository to affect.
|
||||
Args:
|
||||
|
||||
state
|
||||
State in which you want the chocolatey repository.
|
||||
name (str):
|
||||
Name of the repository to affect.
|
||||
|
||||
state (str):
|
||||
State in which you want the chocolatey repository.
|
||||
"""
|
||||
cmd = [_find_chocolatey(), "source", state, "--name", name]
|
||||
result = __salt__["cmd.run_all"](cmd, python_shell=False)
|
||||
|
@ -1229,8 +1260,10 @@ def enable_source(name):
|
|||
"""
|
||||
Instructs Chocolatey to enable a source.
|
||||
|
||||
name
|
||||
Name of the source repository to enable.
|
||||
Args:
|
||||
|
||||
name (str):
|
||||
Name of the source repository to enable.
|
||||
|
||||
CLI Example:
|
||||
|
||||
|
@ -1246,8 +1279,10 @@ def disable_source(name):
|
|||
"""
|
||||
Instructs Chocolatey to disable a source.
|
||||
|
||||
name
|
||||
Name of the source repository to disable.
|
||||
Args:
|
||||
|
||||
name (str):
|
||||
Name of the source repository to disable.
|
||||
|
||||
CLI Example:
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ def installed(
|
|||
default arguments. Default is ``False``.
|
||||
|
||||
force_x86 (bool):
|
||||
Force x86 (32bit) installation on 64-bit systems. Default is
|
||||
Force x86 (32bit) installation on 64bit systems. Default is
|
||||
``False``.
|
||||
|
||||
package_args (str):
|
||||
|
@ -141,9 +141,13 @@ def installed(
|
|||
ret["comment"] = f"{name} {version} is already installed"
|
||||
else:
|
||||
if allow_multiple:
|
||||
ret["comment"] = f"{name} {version} will be installed side by side with {name} {installed_version} if supported"
|
||||
ret[
|
||||
"comment"
|
||||
] = f"{name} {version} will be installed side by side with {name} {installed_version} if supported"
|
||||
else:
|
||||
ret["comment"] = f"{name} {version} will be installed over {name} {installed_version}"
|
||||
ret[
|
||||
"comment"
|
||||
] = f"{name} {version} will be installed over {name} {installed_version}"
|
||||
force = True
|
||||
else:
|
||||
version = installed_version
|
||||
|
@ -307,7 +311,7 @@ def upgraded(
|
|||
the default arguments. Default is ``False``.
|
||||
|
||||
force_x86 (bool):
|
||||
``True`` forces 32-bit installation on 64-bit systems. Default is
|
||||
``True`` forces 32bit installation on 64bit systems. Default is
|
||||
``False``.
|
||||
|
||||
package_args (str):
|
||||
|
@ -370,10 +374,14 @@ def upgraded(
|
|||
if salt.utils.versions.compare(
|
||||
ver1=installed_version, oper="<", ver2=version
|
||||
):
|
||||
ret["comment"] = f"{name} {installed_version} will be upgraded to version {version}"
|
||||
ret[
|
||||
"comment"
|
||||
] = f"{name} {installed_version} will be upgraded to version {version}"
|
||||
# If installed version is newer than new version
|
||||
else:
|
||||
ret["comment"] = f"{name} {installed_version} (newer) is already installed"
|
||||
ret[
|
||||
"comment"
|
||||
] = f"{name} {installed_version} (newer) is already installed"
|
||||
return ret
|
||||
# Catch all for a condition where version is not passed and there is no
|
||||
# available version
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
import pytest
|
||||
|
||||
import salt.utils.path
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.windows_whitelisted,
|
||||
pytest.mark.skip_unless_on_windows,
|
||||
pytest.mark.slow_test,
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def chocolatey(states):
|
||||
if not salt.utils.path.which("choco.exe"):
|
||||
pytest.skip("The `chocolatey` binary is not available")
|
||||
yield states.chocolatey
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def chocolatey_mod(modules):
|
||||
yield modules.chocolatey
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def clean(chocolatey_mod):
|
||||
chocolatey_mod.uninstall(name="vim", force=True)
|
||||
yield
|
||||
chocolatey_mod.uninstall(name="vim", force=True)
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def vim(chocolatey_mod):
|
||||
chocolatey_mod.install(name="vim", version="9.0.1672")
|
||||
yield
|
||||
chocolatey_mod.uninstall(name="vim", force=True)
|
||||
|
||||
|
||||
@pytest.mark.destructive_test
|
||||
def test_installed_latest(clean, chocolatey, chocolatey_mod):
|
||||
chocolatey.installed(name="vim")
|
||||
result = chocolatey_mod.version(name="vim")
|
||||
assert "vim" in result
|
||||
|
||||
|
||||
@pytest.mark.destructive_test
|
||||
def test_installed_version(clean, chocolatey, chocolatey_mod):
|
||||
chocolatey.installed(name="vim", version="9.0.1672")
|
||||
result = chocolatey_mod.version(name="vim")
|
||||
assert "vim" in result
|
||||
assert result["vim"]["installed"][0] == "9.0.1672"
|
||||
|
||||
|
||||
def test_uninstalled(vim, chocolatey, chocolatey_mod):
|
||||
chocolatey.uninstalled(name="vim")
|
||||
result = chocolatey_mod.version(name="vim")
|
||||
assert "vim" not in result
|
||||
|
||||
|
||||
def test_upgraded(vim, chocolatey, chocolatey_mod):
|
||||
result = chocolatey_mod.version(name="vim")
|
||||
assert "vim" in result
|
||||
assert result["vim"]["installed"][0] == "9.0.1672"
|
||||
chocolatey.upgraded(name="vim", version="9.0.1677")
|
||||
result = chocolatey_mod.version(name="vim")
|
||||
assert "vim" in result
|
||||
assert result["vim"]["installed"][0] == "9.0.1677"
|
128
tests/pytests/functional/states/test_chocolatey_1.2.1.py
Normal file
128
tests/pytests/functional/states/test_chocolatey_1.2.1.py
Normal file
|
@ -0,0 +1,128 @@
|
|||
"""
|
||||
Functional tests for chocolatey state
|
||||
"""
|
||||
import os
|
||||
import pathlib
|
||||
|
||||
import pytest
|
||||
|
||||
import salt.utils.path
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.windows_whitelisted,
|
||||
pytest.mark.skip_unless_on_windows,
|
||||
pytest.mark.slow_test,
|
||||
pytest.mark.destructive_test,
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def chocolatey(states):
|
||||
yield states.chocolatey
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def chocolatey_mod(modules):
|
||||
|
||||
url = "https://packages.chocolatey.org/chocolatey.1.2.1.nupkg"
|
||||
with pytest.helpers.temp_file(name="choco.nupkg") as nupkg:
|
||||
choco_pkg = pathlib.Path(str(nupkg))
|
||||
choco_dir = choco_pkg.parent / "choco_dir"
|
||||
choco_script = choco_dir / "tools" / "chocolateyInstall.ps1"
|
||||
|
||||
def install():
|
||||
# Install Chocolatey 1.2.1
|
||||
|
||||
# Download Package
|
||||
modules.cp.get_url(path=url, dest=str(choco_pkg))
|
||||
|
||||
# Unzip Package
|
||||
modules.archive.unzip(
|
||||
zip_file=str(choco_pkg),
|
||||
dest=str(choco_dir),
|
||||
extract_perms=False,
|
||||
)
|
||||
|
||||
# Run installer script
|
||||
assert choco_script.exists()
|
||||
result = modules.cmd.script(
|
||||
source=str(choco_script),
|
||||
cwd=str(choco_script.parent),
|
||||
shell="powershell",
|
||||
python_shell=True,
|
||||
)
|
||||
assert result["retcode"] == 0
|
||||
|
||||
def uninstall():
|
||||
choco_dir = os.environ.get("ChocolateyInstall", False)
|
||||
if choco_dir:
|
||||
# Remove Chocolatey Directory
|
||||
modules.file.remove(path=choco_dir, force=True)
|
||||
# Remove Chocolatey Environment Variables
|
||||
for env_var in modules.environ.items():
|
||||
if env_var.lower().startswith("chocolatey"):
|
||||
modules.environ.setval(
|
||||
key=env_var, val=False, false_unsets=True, permanent="HKLM"
|
||||
)
|
||||
modules.environ.setval(
|
||||
key=env_var, val=False, false_unsets=True, permanent="HKCU"
|
||||
)
|
||||
# Remove Chocolatey from the Path
|
||||
for path in modules.win_path.get_path():
|
||||
if "chocolatey" in path.lower():
|
||||
modules.win_path.remove(path=path, rehash=True)
|
||||
|
||||
# Remove unknown version
|
||||
if salt.utils.path.which("choco.exe"):
|
||||
uninstall()
|
||||
|
||||
# Install known version
|
||||
install()
|
||||
|
||||
yield modules.chocolatey
|
||||
|
||||
# Remove
|
||||
uninstall()
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def clean(chocolatey_mod):
|
||||
chocolatey_mod.uninstall(name="vim", force=True)
|
||||
yield
|
||||
chocolatey_mod.uninstall(name="vim", force=True)
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def vim(chocolatey_mod):
|
||||
chocolatey_mod.install(name="vim", version="9.0.1672")
|
||||
yield
|
||||
chocolatey_mod.uninstall(name="vim", force=True)
|
||||
|
||||
|
||||
def test_installed_latest(clean, chocolatey, chocolatey_mod):
|
||||
chocolatey.installed(name="vim")
|
||||
result = chocolatey_mod.version(name="vim")
|
||||
assert "vim" in result
|
||||
|
||||
|
||||
def test_installed_version(clean, chocolatey, chocolatey_mod):
|
||||
chocolatey.installed(name="vim", version="9.0.1672")
|
||||
result = chocolatey_mod.version(name="vim")
|
||||
assert "vim" in result
|
||||
assert result["vim"]["installed"][0] == "9.0.1672"
|
||||
|
||||
|
||||
def test_uninstalled(vim, chocolatey, chocolatey_mod):
|
||||
chocolatey.uninstalled(name="vim")
|
||||
result = chocolatey_mod.version(name="vim")
|
||||
assert "vim" not in result
|
||||
|
||||
|
||||
def test_upgraded(vim, chocolatey, chocolatey_mod):
|
||||
result = chocolatey_mod.version(name="vim")
|
||||
assert "vim" in result
|
||||
assert result["vim"]["installed"][0] == "9.0.1672"
|
||||
chocolatey.upgraded(name="vim", version="9.0.1677")
|
||||
result = chocolatey_mod.version(name="vim")
|
||||
assert "vim" in result
|
||||
assert result["vim"]["installed"][0] == "9.0.1677"
|
128
tests/pytests/functional/states/test_chocolatey_latest.py
Normal file
128
tests/pytests/functional/states/test_chocolatey_latest.py
Normal file
|
@ -0,0 +1,128 @@
|
|||
"""
|
||||
Functional tests for chocolatey state
|
||||
"""
|
||||
import os
|
||||
import pathlib
|
||||
|
||||
import pytest
|
||||
|
||||
import salt.utils.path
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.windows_whitelisted,
|
||||
pytest.mark.skip_unless_on_windows,
|
||||
pytest.mark.slow_test,
|
||||
pytest.mark.destructive_test,
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def chocolatey(states):
|
||||
yield states.chocolatey
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def chocolatey_mod(modules):
|
||||
|
||||
url = "https://community.chocolatey.org/api/v2/package/chocolatey/"
|
||||
with pytest.helpers.temp_file(name="choco.nupkg") as nupkg:
|
||||
choco_pkg = pathlib.Path(str(nupkg))
|
||||
choco_dir = choco_pkg.parent / "choco_dir"
|
||||
choco_script = choco_dir / "tools" / "chocolateyInstall.ps1"
|
||||
|
||||
def install():
|
||||
# Install Chocolatey 1.2.1
|
||||
|
||||
# Download Package
|
||||
modules.cp.get_url(path=url, dest=str(choco_pkg))
|
||||
|
||||
# Unzip Package
|
||||
modules.archive.unzip(
|
||||
zip_file=str(choco_pkg),
|
||||
dest=str(choco_dir),
|
||||
extract_perms=False,
|
||||
)
|
||||
|
||||
# Run installer script
|
||||
assert choco_script.exists()
|
||||
result = modules.cmd.script(
|
||||
source=str(choco_script),
|
||||
cwd=str(choco_script.parent),
|
||||
shell="powershell",
|
||||
python_shell=True,
|
||||
)
|
||||
assert result["retcode"] == 0
|
||||
|
||||
def uninstall():
|
||||
choco_dir = os.environ.get("ChocolateyInstall", False)
|
||||
if choco_dir:
|
||||
# Remove Chocolatey Directory
|
||||
modules.file.remove(path=choco_dir, force=True)
|
||||
# Remove Chocolatey Environment Variables
|
||||
for env_var in modules.environ.items():
|
||||
if env_var.lower().startswith("chocolatey"):
|
||||
modules.environ.setval(
|
||||
key=env_var, val=False, false_unsets=True, permanent="HKLM"
|
||||
)
|
||||
modules.environ.setval(
|
||||
key=env_var, val=False, false_unsets=True, permanent="HKCU"
|
||||
)
|
||||
# Remove Chocolatey from the Path
|
||||
for path in modules.win_path.get_path():
|
||||
if "chocolatey" in path.lower():
|
||||
modules.win_path.remove(path=path, rehash=True)
|
||||
|
||||
# Remove unknown version
|
||||
if salt.utils.path.which("choco.exe"):
|
||||
uninstall()
|
||||
|
||||
# Install known version
|
||||
install()
|
||||
|
||||
yield modules.chocolatey
|
||||
|
||||
# Remove
|
||||
uninstall()
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def clean(chocolatey_mod):
|
||||
chocolatey_mod.uninstall(name="vim", force=True)
|
||||
yield
|
||||
chocolatey_mod.uninstall(name="vim", force=True)
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def vim(chocolatey_mod):
|
||||
chocolatey_mod.install(name="vim", version="9.0.1672")
|
||||
yield
|
||||
chocolatey_mod.uninstall(name="vim", force=True)
|
||||
|
||||
|
||||
def test_installed_latest(clean, chocolatey, chocolatey_mod):
|
||||
chocolatey.installed(name="vim")
|
||||
result = chocolatey_mod.version(name="vim")
|
||||
assert "vim" in result
|
||||
|
||||
|
||||
def test_installed_version(clean, chocolatey, chocolatey_mod):
|
||||
chocolatey.installed(name="vim", version="9.0.1672")
|
||||
result = chocolatey_mod.version(name="vim")
|
||||
assert "vim" in result
|
||||
assert result["vim"]["installed"][0] == "9.0.1672"
|
||||
|
||||
|
||||
def test_uninstalled(vim, chocolatey, chocolatey_mod):
|
||||
chocolatey.uninstalled(name="vim")
|
||||
result = chocolatey_mod.version(name="vim")
|
||||
assert "vim" not in result
|
||||
|
||||
|
||||
def test_upgraded(vim, chocolatey, chocolatey_mod):
|
||||
result = chocolatey_mod.version(name="vim")
|
||||
assert "vim" in result
|
||||
assert result["vim"]["installed"][0] == "9.0.1672"
|
||||
chocolatey.upgraded(name="vim", version="9.0.1677")
|
||||
result = chocolatey_mod.version(name="vim")
|
||||
assert "vim" in result
|
||||
assert result["vim"]["installed"][0] == "9.0.1677"
|
|
@ -1,8 +1,6 @@
|
|||
"""
|
||||
Test for the chocolatey module
|
||||
"""
|
||||
|
||||
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
"""
|
||||
Unit tests for chocolatey state
|
||||
"""
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
|
||||
import salt.modules.chocolatey as chocolatey_mod
|
||||
import salt.modules.cmdmod as cmdmod
|
||||
import salt.states.chocolatey as chocolatey
|
||||
from tests.support.mock import MagicMock, patch
|
||||
|
||||
|
@ -112,4 +114,3 @@ def test_source_present(list_sources):
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue