pkgin latest_version bugfix

Handle case where the currently installed package is the latest
This commit is contained in:
Travis Paul 2018-05-24 15:27:28 +08:00 committed by rallytime
parent 4ae0313797
commit 4dac0b4a31
No known key found for this signature in database
GPG key ID: E8F1A4B90D0DEA19
2 changed files with 21 additions and 1 deletions

View file

@ -192,7 +192,7 @@ def latest_version(*names, **kwargs):
s = _splitpkg(p[0])
if s:
if not s[0] in pkglist:
if len(p) > 1 and p[1] == '<' or p[1] == '':
if len(p) > 1 and p[1] in ('<', '', '='):
pkglist[s[0]] = s[1]
else:
pkglist[s[0]] = ''

View file

@ -113,6 +113,26 @@ class PkginTestCase(TestCase, LoaderModuleMockMixin):
patch.dict(pkgin.__salt__, {'cmd.run': pkgin_search_cmd}):
self.assertEqual(pkgin.latest_version('somepkg'), '1.1')
'''
Test getting the latest version of an installed package that is the latest version
'''
pkgin_out = [
'somepkg-1.2;=;Some package description here',
'',
'=: package is installed and up-to-date',
'<: package is installed but newer version is available',
'>: installed package has a greater version than available package'
]
pkgin_refresh_db_mock = MagicMock(return_value=True)
pkgin_search_cmd = MagicMock(return_value=os.linesep.join(pkgin_out))
with patch('salt.modules.pkgin.refresh_db', pkgin_refresh_db_mock), \
patch('salt.modules.pkgin._get_version', pkgin__get_version_mock), \
patch('salt.modules.pkgin._check_pkgin', pkgin__check_pkgin_mock), \
patch.dict(pkgin.__salt__, {'cmd.run': pkgin_search_cmd}):
self.assertEqual(pkgin.latest_version('somepkg'), '1.2')
'''
Test getting the latest version of a bogus package
'''