mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
test cleanup, removing nesting, using params.
This commit is contained in:
parent
2870b50b26
commit
62d01b5bff
2 changed files with 97 additions and 84 deletions
|
@ -3065,7 +3065,6 @@ def test_linux_cpu_data():
|
|||
assert "cpu_flags" in ret
|
||||
assert "cpu_model" in ret
|
||||
|
||||
cpuinfo_list = []
|
||||
cpuinfo_dict = {
|
||||
"Processor": "ARMv6-compatible processor rev 7 (v6l)",
|
||||
"BogoMIPS": "697.95",
|
||||
|
@ -4192,7 +4191,13 @@ def test__systemd():
|
|||
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"
|
||||
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"
|
||||
)
|
||||
),
|
||||
},
|
||||
):
|
||||
|
@ -4200,15 +4205,17 @@ def test__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["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"
|
||||
)
|
||||
|
||||
|
||||
def test__clean_value(caplog):
|
||||
def test__clean_value_uuid(caplog):
|
||||
"""
|
||||
test _clean_value
|
||||
test _clean_value uuid
|
||||
"""
|
||||
ret = core._clean_value("key", None)
|
||||
assert not ret
|
||||
|
@ -4226,43 +4233,50 @@ def test__clean_value(caplog):
|
|||
in caplog.messages
|
||||
)
|
||||
|
||||
values = [
|
||||
["kernelrelease", "10.0.14393", "10.0.14393"],
|
||||
["kernelversion", "10.0.14393", "10.0.14393"],
|
||||
["osversion", "10.0.14393", "10.0.14393"],
|
||||
["osrelease", "2016Server", "2016Server"],
|
||||
["osrelease", "to be filled", None],
|
||||
["osmanufacturer", "Microsoft Corporation", "Microsoft Corporation"],
|
||||
["manufacturer", "innotek GmbH", "innotek GmbH"],
|
||||
["manufacturer", "to be filled", None],
|
||||
["productname", "VirtualBox", "VirtualBox"],
|
||||
["biosversion", "Default System BIOS", "Default System BIOS"],
|
||||
["serialnumber", "0", None],
|
||||
[
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"grain,value,expected",
|
||||
(
|
||||
("kernelrelease", "10.0.14393", "10.0.14393"),
|
||||
("kernelversion", "10.0.14393", "10.0.14393"),
|
||||
("osversion", "10.0.14393", "10.0.14393"),
|
||||
("osrelease", "2016Server", "2016Server"),
|
||||
("osrelease", "to be filled", None),
|
||||
("osmanufacturer", "Microsoft Corporation", "Microsoft Corporation"),
|
||||
("manufacturer", "innotek GmbH", "innotek GmbH"),
|
||||
("manufacturer", "to be filled", None),
|
||||
("productname", "VirtualBox", "VirtualBox"),
|
||||
("biosversion", "Default System BIOS", "Default System BIOS"),
|
||||
("serialnumber", "0", None),
|
||||
(
|
||||
"osfullname",
|
||||
"Microsoft Windows Server 2016 Datacenter",
|
||||
"Microsoft Windows Server 2016 Datacenter",
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
"timezone",
|
||||
"(UTC-08:00) Pacific Time (US & Canada)",
|
||||
"(UTC-08:00) Pacific Time (US & Canada)",
|
||||
],
|
||||
[
|
||||
),
|
||||
(
|
||||
"uuid",
|
||||
"d013f373-7331-4a9f-848b-72e379fbe7bf",
|
||||
"d013f373-7331-4a9f-848b-72e379fbe7bf",
|
||||
],
|
||||
["windowsdomain", "WORKGROUP", "WORKGROUP"],
|
||||
["windowsdomaintype", "Workgroup", "Workgroup"],
|
||||
["motherboard.productname", "VirtualBox", "VirtualBox"],
|
||||
["motherboard.serialnumber", "0", None],
|
||||
["model_name", "Macbook Pro", "Macbook Pro"],
|
||||
["system_serialnumber", "W80322MWATM", "W80322MWATM"],
|
||||
]
|
||||
for value in values:
|
||||
ret = core._clean_value(value[0], value[1])
|
||||
assert ret == value[2]
|
||||
),
|
||||
("windowsdomain", "WORKGROUP", "WORKGROUP"),
|
||||
("windowsdomaintype", "Workgroup", "Workgroup"),
|
||||
("motherboard.productname", "VirtualBox", "VirtualBox"),
|
||||
("motherboard.serialnumber", "0", None),
|
||||
("model_name", "Macbook Pro", "Macbook Pro"),
|
||||
("system_serialnumber", "W80322MWATM", "W80322MWATM"),
|
||||
),
|
||||
)
|
||||
def test__clean_value_multiple_values(grain, value, expected):
|
||||
"""
|
||||
test _clean_value multiple values
|
||||
"""
|
||||
ret = core._clean_value(grain, value)
|
||||
assert ret == expected
|
||||
|
||||
|
||||
def test__linux_init_system(caplog):
|
||||
|
|
|
@ -139,55 +139,54 @@ def test_rename(tmp_path):
|
|||
assert filestate.rename(name, source) == ret
|
||||
|
||||
mock_lex = MagicMock(side_effect=[True, False, False])
|
||||
with patch.object(os.path, "isabs", mock_t):
|
||||
with patch.object(os.path, "lexists", mock_lex):
|
||||
with patch.object(os.path, "isdir", mock_f):
|
||||
with patch.dict(
|
||||
filestate.__salt__,
|
||||
{
|
||||
"file.makedirs": MagicMock(
|
||||
side_effect=filestate.CommandExecutionError()
|
||||
)
|
||||
},
|
||||
):
|
||||
with patch.object(os.path, "islink", mock_f):
|
||||
with patch.dict(filestate.__opts__, {"test": False}):
|
||||
with patch.object(shutil, "move", MagicMock()):
|
||||
if salt.utils.platform.is_windows():
|
||||
comt = "Drive C: is not mapped"
|
||||
else:
|
||||
comt = "Drive is not mapped"
|
||||
ret.update(
|
||||
{
|
||||
"name": name,
|
||||
"comment": comt,
|
||||
"result": False,
|
||||
"changes": {},
|
||||
}
|
||||
)
|
||||
assert (
|
||||
filestate.rename(name, source, makedirs=True) == ret
|
||||
)
|
||||
with patch.object(os.path, "isabs", mock_t), patch.object(
|
||||
os.path, "lexists", mock_lex
|
||||
), patch.object(os.path, "isdir", mock_f), patch.dict(
|
||||
filestate.__salt__,
|
||||
{"file.makedirs": MagicMock(side_effect=filestate.CommandExecutionError())},
|
||||
), patch.object(
|
||||
os.path, "islink", mock_f
|
||||
), patch.dict(
|
||||
filestate.__opts__, {"test": False}
|
||||
), patch.object(
|
||||
shutil, "move", MagicMock()
|
||||
):
|
||||
if salt.utils.platform.is_windows():
|
||||
comt = "Drive C: is not mapped"
|
||||
else:
|
||||
comt = "Drive is not mapped"
|
||||
ret.update(
|
||||
{
|
||||
"name": name,
|
||||
"comment": comt,
|
||||
"result": False,
|
||||
"changes": {},
|
||||
}
|
||||
)
|
||||
assert filestate.rename(name, source, makedirs=True) == ret
|
||||
|
||||
mock_lex = MagicMock(side_effect=[True, False, False])
|
||||
mock_link = str(tmp_path / "salt" / "link")
|
||||
with patch.object(os.path, "isabs", mock_t):
|
||||
with patch.object(os.path, "lexists", mock_lex):
|
||||
with patch.object(os.path, "isdir", mock_t):
|
||||
with patch.object(os.path, "islink", mock_t):
|
||||
with patch(
|
||||
"salt.utils.path.readlink", MagicMock(return_value=mock_link)
|
||||
):
|
||||
with patch.dict(filestate.__opts__, {"test": False}):
|
||||
with patch.object(os, "symlink", MagicMock()):
|
||||
with patch.object(os, "unlink", MagicMock()):
|
||||
comt = 'Moved "{}" to "{}"'.format(source, name)
|
||||
ret.update(
|
||||
{
|
||||
"name": name,
|
||||
"comment": comt,
|
||||
"result": True,
|
||||
"changes": {name: source},
|
||||
}
|
||||
)
|
||||
assert filestate.rename(name, source) == ret
|
||||
with patch.object(os.path, "isabs", mock_t), patch.object(
|
||||
os.path, "lexists", mock_lex
|
||||
), patch.object(os.path, "isdir", mock_t), patch.object(
|
||||
os.path, "islink", mock_t
|
||||
), patch(
|
||||
"salt.utils.path.readlink", MagicMock(return_value=mock_link)
|
||||
), patch.dict(
|
||||
filestate.__opts__, {"test": False}
|
||||
), patch.object(
|
||||
os, "symlink", MagicMock()
|
||||
), patch.object(
|
||||
os, "unlink", MagicMock()
|
||||
):
|
||||
comt = 'Moved "{}" to "{}"'.format(source, name)
|
||||
ret.update(
|
||||
{
|
||||
"name": name,
|
||||
"comment": comt,
|
||||
"result": True,
|
||||
"changes": {name: source},
|
||||
}
|
||||
)
|
||||
assert filestate.rename(name, source) == ret
|
||||
|
|
Loading…
Add table
Reference in a new issue