Skip to content

Commit

Permalink
Bump functional test splits to 4
Browse files Browse the repository at this point in the history
  • Loading branch information
s0undt3ch authored and Akm0d committed Mar 22, 2024
1 parent 7c82f37 commit d0b014b
Showing 1 changed file with 107 additions and 4 deletions.
111 changes: 107 additions & 4 deletions tests/pytests/unit/modules/test_pacmanpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import pytest

import salt.modules.pacmanpkg as pacman
from tests.support.mock import MagicMock, patch
import salt.utils.systemd
from tests.support.mock import MagicMock, patch


@pytest.fixture
def configure_loader_modules():
return {
pacman: {},
}
return {pacman: {}}


def test_list_pkgs():
Expand Down Expand Up @@ -66,6 +64,111 @@ def test_list_pkgs_as_list():
assert stringifymock.call_count == 0


def test_list_pkgs_no_context():
"""
Test if it list the packages currently installed in a dict
"""
cmdmock = MagicMock(return_value="A 1.0\nB 2.0")
sortmock = MagicMock()
stringifymock = MagicMock()
mock_ret = {"A": ["1.0"], "B": ["2.0"]}
with patch.dict(
pacman.__salt__,
{
"cmd.run": cmdmock,
"pkg_resource.add_pkg": lambda pkgs, name, version: pkgs.setdefault(
name, []
).append(version),
"pkg_resource.sort_pkglist": sortmock,
"pkg_resource.stringify": stringifymock,
},
), patch.object(pacman, "_list_pkgs_from_context") as list_pkgs_context_mock:
assert pacman.list_pkgs() == mock_ret

pkgs = pacman.list_pkgs(versions_as_list=True, use_context=False)
list_pkgs_context_mock.assert_not_called()
list_pkgs_context_mock.reset_mock()

pkgs = pacman.list_pkgs(versions_as_list=True, use_context=False)
list_pkgs_context_mock.assert_not_called()
list_pkgs_context_mock.reset_mock()


def test_group_list():
"""
Test if it lists the available groups
"""

def cmdlist(cmd, **kwargs):
"""
Handle several different commands being run
"""
if cmd == ["pacman", "-Sgg"]:
return (
"group-a pkg1\ngroup-a pkg2\ngroup-f pkg9\ngroup-c pkg3\ngroup-b pkg4"
)
elif cmd == ["pacman", "-Qg"]:
return "group-a pkg1\ngroup-b pkg4"
else:
return f"Untested command ({cmd}, {kwargs})!"

cmdmock = MagicMock(side_effect=cmdlist)

sortmock = MagicMock()
with patch.dict(
pacman.__salt__, {"cmd.run": cmdmock, "pkg_resource.sort_pkglist": sortmock}
):
assert pacman.group_list() == {
"available": ["group-c", "group-f"],
"installed": ["group-b"],
"partially_installed": ["group-a"],
}


def test_group_info():
"""
Test if it shows the packages in a group
"""

def cmdlist(cmd, **kwargs):
"""
Handle several different commands being run
"""
if cmd == ["pacman", "-Sgg", "testgroup"]:
return "testgroup pkg1\ntestgroup pkg2"
else:
return f"Untested command ({cmd}, {kwargs})!"

cmdmock = MagicMock(side_effect=cmdlist)

sortmock = MagicMock()
with patch.dict(
pacman.__salt__, {"cmd.run": cmdmock, "pkg_resource.sort_pkglist": sortmock}
):
assert pacman.group_info("testgroup")["default"] == ["pkg1", "pkg2"]


def test_group_diff():
"""
Test if it shows the difference between installed and target group contents
"""

listmock = MagicMock(return_value={"A": ["1.0"], "B": ["2.0"]})
groupmock = MagicMock(
return_value={
"mandatory": [],
"optional": [],
"default": ["A", "C"],
"conditional": [],
}
)
with patch.dict(
pacman.__salt__, {"pkg.list_pkgs": listmock, "pkg.group_info": groupmock}
):
results = pacman.group_diff("testgroup")
assert results["default"] == {"installed": ["A"], "not installed": ["C"]}


def test_pacman_install_sysupgrade_flag():
"""
Test if the pacman.install function appends the '-u' flag only when sysupgrade is True
Expand Down

0 comments on commit d0b014b

Please sign in to comment.