Add lowpkg tests for version comparison

This commit is contained in:
Bo Maryniuk 2016-03-30 17:33:24 +02:00
parent afdf451d87
commit f07c7ea792

View File

@ -95,6 +95,28 @@ class RpmTestCase(TestCase):
self.assertDictEqual(rpm.owner('/usr/bin/python', '/usr/bin/vim'),
ret)
@patch('salt.modules.rpm.HAS_RPM', True)
def test_version_cmp_rpm(self):
'''
Test package version is called RPM version if RPM-Python is installed
:return:
'''
rpm.rpm = MagicMock(return_value=MagicMock)
with patch('salt.modules.rpm.rpm.labelCompare', MagicMock(return_value=0)):
self.assertEqual(0, rpm.version_cmp('1', '2')) # mock returns 0, which means RPM was called
@patch('salt.modules.rpm.HAS_RPM', False)
def test_version_cmp_fallback(self):
'''
Test package version is called RPM version if RPM-Python is installed
:return:
'''
rpm.rpm = MagicMock(return_value=MagicMock)
with patch('salt.modules.rpm.rpm.labelCompare', MagicMock(return_value=0)):
self.assertEqual(-1, rpm.version_cmp('1', '2')) # mock returns -1, a python implementation was called
if __name__ == '__main__':
from integration import run_tests