From 2e9774ca6e938d814dc7df9a6a5a2667dcb47b7e Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Thu, 27 Apr 2023 16:15:07 +0100 Subject: [PATCH] Add regression test for https://github.com/saltstack/salt/issues/64118 Signed-off-by: Pedro Algarvio --- tests/pytests/unit/states/test_pkg.py | 46 ++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/tests/pytests/unit/states/test_pkg.py b/tests/pytests/unit/states/test_pkg.py index b852f27b008b..f58be11011fc 100644 --- a/tests/pytests/unit/states/test_pkg.py +++ b/tests/pytests/unit/states/test_pkg.py @@ -3,6 +3,7 @@ import pytest import salt.modules.beacons as beaconmod +import salt.modules.cp as cp import salt.modules.pkg_resource as pkg_resource import salt.modules.yumpkg as yumpkg import salt.states.beacon as beaconstate @@ -15,19 +16,28 @@ @pytest.fixture -def configure_loader_modules(): +def configure_loader_modules(minion_opts): return { + cp: { + "__opts__": minion_opts, + }, pkg: { "__env__": "base", "__salt__": {}, "__grains__": {"os": "CentOS", "os_family": "RedHat"}, - "__opts__": {"test": False, "cachedir": ""}, + "__opts__": minion_opts, "__instance_id__": "", "__low__": {}, "__utils__": {"state.gen_tag": state_utils.gen_tag}, }, - beaconstate: {"__salt__": {}, "__opts__": {}}, - beaconmod: {"__salt__": {}, "__opts__": {}}, + beaconstate: { + "__salt__": {}, + "__opts__": minion_opts, + }, + beaconmod: { + "__salt__": {}, + "__opts__": minion_opts, + }, pkg_resource: { "__salt__": {}, "__grains__": {"os": "CentOS", "os_family": "RedHat"}, @@ -35,7 +45,7 @@ def configure_loader_modules(): yumpkg: { "__salt__": {}, "__grains__": {"osarch": "x86_64", "osmajorrelease": 7}, - "__opts__": {}, + "__opts__": minion_opts, }, } @@ -563,6 +573,32 @@ def test_installed_with_changes_test_true(list_pkgs): assert ret["changes"] == expected +def test_installed_with_sources(list_pkgs, tmp_path): + """ + Test pkg.installed with passing `sources` + """ + + list_pkgs = MagicMock(return_value=list_pkgs) + pkg_source = tmp_path / "pkga-package-0.3.0.deb" + + with patch.dict( + pkg.__salt__, + { + "cp.cache_file": cp.cache_file, + "pkg.list_pkgs": list_pkgs, + "pkg_resource.pack_sources": pkg_resource.pack_sources, + "lowpkg.bin_pkg_info": MagicMock(), + }, + ), patch("salt.fileclient.get_file_client", return_value=MagicMock()): + try: + ret = pkg.installed("install-pkgd", sources=[{"pkga": str(pkg_source)}]) + assert ret["result"] is False + except TypeError as exc: + if "got multiple values for keyword argument 'saltenv'" in str(exc): + pytest.fail(f"TypeError should have not been raised: {exc}") + raise exc from None + + @pytest.mark.parametrize("action", ["removed", "purged"]) def test_removed_purged_with_changes_test_true(list_pkgs, action): """