mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Add some new and fix unit tests
This commit is contained in:
parent
767303a3dc
commit
69696e6fd7
2 changed files with 48 additions and 5 deletions
|
@ -21,7 +21,7 @@ def test_mocked_objects():
|
|||
for k, v in salt.version.SaltStackVersion.LNAMES.items():
|
||||
assert k == k.lower()
|
||||
assert isinstance(v, tuple)
|
||||
if sv.new_version(major=v[0]) and not sv.can_have_dot_zero(major=v[0]):
|
||||
if sv.new_version(major=v[0]):
|
||||
assert len(v) == 1
|
||||
else:
|
||||
assert len(v) == 2
|
||||
|
@ -64,6 +64,13 @@ def test_get_release_number_success_new_version():
|
|||
assert salt_version.get_release_number("Neon") == "3000"
|
||||
|
||||
|
||||
def test_get_release_number_success_new_version_with_dot():
|
||||
"""
|
||||
Test that a version is returned for new versioning (3006)
|
||||
"""
|
||||
assert salt_version.get_release_number("Sulfur") == "3006"
|
||||
|
||||
|
||||
def test_equal_success():
|
||||
"""
|
||||
Test that the current version is equal to the codename
|
||||
|
@ -83,6 +90,16 @@ def test_equal_success_new_version():
|
|||
assert salt_version.equal("foo") is True
|
||||
|
||||
|
||||
def test_equal_success_new_version_with_dot():
|
||||
"""
|
||||
Test that the current version is equal to the codename
|
||||
while using the new versioning
|
||||
"""
|
||||
with patch("salt.version.SaltStackVersion", MagicMock(return_value="3006.1")):
|
||||
with patch("salt.version.SaltStackVersion.LNAMES", {"foo": (3006,)}):
|
||||
assert salt_version.equal("foo") is True
|
||||
|
||||
|
||||
def test_equal_older_codename():
|
||||
"""
|
||||
Test that when an older codename is passed in, the function returns False.
|
||||
|
@ -142,6 +159,17 @@ def test_greater_than_success_new_version():
|
|||
assert salt_version.greater_than("Nitrogen") is True
|
||||
|
||||
|
||||
def test_greater_than_success_new_version_with_dot():
|
||||
"""
|
||||
Test that the current version is newer than the codename
|
||||
"""
|
||||
with patch(
|
||||
"salt.modules.salt_version.get_release_number", MagicMock(return_value="3000")
|
||||
):
|
||||
with patch("salt.version.SaltStackVersion", MagicMock(return_value="3006.0")):
|
||||
assert salt_version.greater_than("Neon") is True
|
||||
|
||||
|
||||
def test_greater_than_with_equal_codename():
|
||||
"""
|
||||
Test that when an equal codename is passed in, the function returns False.
|
||||
|
@ -200,6 +228,19 @@ def test_less_than_success_new_version():
|
|||
assert salt_version.less_than("Fluorine") is True
|
||||
|
||||
|
||||
def test_less_than_success_new_version_with_dot():
|
||||
"""
|
||||
Test that when a newer codename is passed in, the function returns True
|
||||
using new version
|
||||
"""
|
||||
with patch("salt.version.SaltStackVersion", MagicMock(return_value="2018.3.2")):
|
||||
with patch(
|
||||
"salt.modules.salt_version.get_release_number",
|
||||
MagicMock(return_value="3006"),
|
||||
):
|
||||
assert salt_version.less_than("Fluorine") is True
|
||||
|
||||
|
||||
def test_less_than_with_equal_codename():
|
||||
"""
|
||||
Test that when an equal codename is passed in, the function returns False.
|
||||
|
|
|
@ -187,7 +187,7 @@ def test_string_new_version_minor():
|
|||
ver = SaltStackVersion(major=maj_ver, minor=min_ver)
|
||||
assert ver.minor == min_ver
|
||||
assert not ver.bugfix
|
||||
assert ver.string == "{}.{}".format(maj_ver, min_ver)
|
||||
assert ver.string == f"{maj_ver}.{min_ver}"
|
||||
|
||||
|
||||
def test_string_new_version_minor_as_string():
|
||||
|
@ -201,13 +201,13 @@ def test_string_new_version_minor_as_string():
|
|||
ver = SaltStackVersion(major=maj_ver, minor=min_ver)
|
||||
assert ver.minor == int(min_ver)
|
||||
assert not ver.bugfix
|
||||
assert ver.string == "{}.{}".format(maj_ver, min_ver)
|
||||
assert ver.string == f"{maj_ver}.{min_ver}"
|
||||
|
||||
# This only seems to happen on a cloned repo without its tags
|
||||
maj_ver = "3000"
|
||||
min_ver = ""
|
||||
ver = SaltStackVersion(major=maj_ver, minor=min_ver)
|
||||
assert ver.minor is None, "{!r} is not {!r}".format(ver.minor, min_ver)
|
||||
assert ver.minor is None, f"{ver.minor!r} is not {min_ver!r}"
|
||||
assert not ver.bugfix
|
||||
assert ver.string == maj_ver
|
||||
|
||||
|
@ -222,7 +222,7 @@ def test_string_old_version():
|
|||
min_ver = "2"
|
||||
ver = SaltStackVersion(major=maj_ver, minor=min_ver)
|
||||
assert ver.bugfix == 0
|
||||
assert ver.string == "{}.{}.0".format(maj_ver, min_ver)
|
||||
assert ver.string == f"{maj_ver}.{min_ver}.0"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -537,6 +537,8 @@ def test_versions_report_no_extensions_available():
|
|||
("3000.1", "3000.1", "Neon"),
|
||||
("3005", "3005", "Phosphorus"),
|
||||
("3006", "3006.0", "Sulfur"),
|
||||
("3006.0", "3006.0", "Sulfur"),
|
||||
("3006.1", "3006.1", "Sulfur"),
|
||||
("3015.1", "3015.1", "Manganese"),
|
||||
("3109.3", "3109.3", None),
|
||||
],
|
||||
|
|
Loading…
Add table
Reference in a new issue