Skip to content

Commit

Permalink
Add more cases to test grains.core._systemd
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhestkov committed Aug 28, 2024
1 parent ccfa952 commit 576d91f
Showing 1 changed file with 64 additions and 17 deletions.
81 changes: 64 additions & 17 deletions tests/pytests/unit/grains/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4185,34 +4185,81 @@ def test__selinux():
assert ret == {"enabled": True, "enforced": "Disabled"}


def test__systemd():
@pytest.mark.parametrize(
"systemd_data,expected",
(
(
{
"pid": 1234,
"retcode": 0,
"stdout": "systemd 254 (254.3-1)\n+PAM +AUDIT -SELINUX -APPARMOR -IMA +SMACK "
"+SECCOMP +GCRYPT +GNUTLS +OPENSSL +ACL +BLKID +CURL +ELFUTILS "
"+FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP +LIBFDISK +PCRE2 "
"-PWQUALITY +P11KIT -QRENCODE +TPM2 +BZIP2 +LZ4 +XZ +ZLIB +ZSTD "
"+BPF_FRAMEWORK +XKBCOMMON +UTMP -SYSVINIT default-hierarchy=unified",
"stderr": "",
},
{
"version": "254",
"features": "+PAM +AUDIT -SELINUX -APPARMOR -IMA +SMACK +SECCOMP +GCRYPT +GNUTLS +OPENSSL "
"+ACL +BLKID +CURL +ELFUTILS +FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP "
"+LIBFDISK +PCRE2 -PWQUALITY +P11KIT -QRENCODE +TPM2 +BZIP2 +LZ4 +XZ "
"+ZLIB +ZSTD +BPF_FRAMEWORK +XKBCOMMON +UTMP -SYSVINIT default-hierarchy=unified",
},
),
(
{
"pid": 2345,
"retcode": 1,
"stdout": "",
"stderr": "some garbage in the output",
},
{
"version": "UNDEFINED",
"features": "",
},
),
(
{
"pid": 3456,
"retcode": 0,
"stdout": "unexpected stdout\none more line",
"stderr": "",
},
{
"version": "UNDEFINED",
"features": "",
},
),
(
{
"pid": 4567,
"retcode": 0,
"stdout": "",
"stderr": "",
},
{
"version": "UNDEFINED",
"features": "",
},
),
),
)
def test__systemd(systemd_data, expected):
"""
test _systemd
"""
with patch.dict(
core.__salt__,
{
"cmd.run": MagicMock(
return_value=(
"systemd 254 (254.3-1)\n+PAM +AUDIT -SELINUX -APPARMOR -IMA +SMACK "
"+SECCOMP +GCRYPT +GNUTLS +OPENSSL +ACL +BLKID +CURL +ELFUTILS "
"+FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP +LIBFDISK +PCRE2 "
"-PWQUALITY +P11KIT -QRENCODE +TPM2 +BZIP2 +LZ4 +XZ +ZLIB +ZSTD "
"+BPF_FRAMEWORK +XKBCOMMON +UTMP -SYSVINIT default-hierarchy=unified"
)
),
"cmd.run_all": MagicMock(return_value=systemd_data),
},
):
ret = core._systemd()
assert "version" in ret
assert "features" in ret
assert ret["version"] == "254"
assert ret["features"] == (
"+PAM +AUDIT -SELINUX -APPARMOR -IMA +SMACK +SECCOMP +GCRYPT +GNUTLS +OPENSSL "
"+ACL +BLKID +CURL +ELFUTILS +FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP "
"+LIBFDISK +PCRE2 -PWQUALITY +P11KIT -QRENCODE +TPM2 +BZIP2 +LZ4 +XZ "
"+ZLIB +ZSTD +BPF_FRAMEWORK +XKBCOMMON +UTMP -SYSVINIT default-hierarchy=unified"
)
assert ret["version"] == expected["version"]
assert ret["features"] == expected["features"]


def test__clean_value_uuid(caplog):
Expand Down

0 comments on commit 576d91f

Please sign in to comment.