mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
unit tests for rpm.checksum() and zypper.download()
This commit is contained in:
parent
a65071a6d1
commit
6b6febb211
3 changed files with 60 additions and 0 deletions
|
@ -95,6 +95,22 @@ class RpmTestCase(TestCase):
|
|||
self.assertDictEqual(rpm.owner('/usr/bin/python', '/usr/bin/vim'),
|
||||
ret)
|
||||
|
||||
# 'checksum' function tests: 1
|
||||
|
||||
def test_checksum(self):
|
||||
'''
|
||||
Test if checksum validate as expected
|
||||
'''
|
||||
ret = {
|
||||
"file1.rpm": True,
|
||||
"file2.rpm": False,
|
||||
"file3.rpm": False,
|
||||
}
|
||||
|
||||
mock = MagicMock(side_effect=[True, 0, True, 1, False, 0])
|
||||
with patch.dict(rpm.__salt__, {'file.file_exists': mock, 'cmd.retcode': mock}):
|
||||
self.assertDictEqual(rpm.checksum("file1.rpm", "file2.rpm", "file3.rpm"), ret)
|
||||
|
||||
@patch('salt.modules.rpm.HAS_RPM', True)
|
||||
def test_version_cmp_rpm(self):
|
||||
'''
|
||||
|
|
19
tests/unit/modules/zypp/zypper-download.xml
Normal file
19
tests/unit/modules/zypp/zypper-download.xml
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?xml version='1.0'?>
|
||||
<stream>
|
||||
<message type="info">Loading repository data...</message>
|
||||
<message type="info">Reading installed packages...</message>
|
||||
<message type="warning">Argument resolves to no package: foo</message>
|
||||
<progress id="" name="(1/1) /var/cache/zypp/packages/SLE-12-x86_64-Pool/x86_64/nmap-6.46-1.72.x86_64.rpm"/>
|
||||
<download-result>
|
||||
<solvable>
|
||||
<kind>package</kind>
|
||||
<name>nmap</name>
|
||||
<edition epoch="0" version="6.46" release="1.72"/>
|
||||
<arch>x86_64</arch>
|
||||
<repository name="SLE-12-x86_64-Pool" alias="SLE-12-x86_64-Pool"/>
|
||||
</solvable>
|
||||
<localfile path="/var/cache/zypp/packages/SLE-12-x86_64-Pool/x86_64/nmap-6.46-1.72.x86_64.rpm"/>
|
||||
</download-result>
|
||||
<progress id="" name="(1/1) /var/cache/zypp/packages/SLE-12-x86_64-Pool/x86_64/nmap-6.46-1.72.x86_64.rpm" done="0"/>
|
||||
<message type="info">download: Done.</message>
|
||||
</stream>
|
|
@ -355,6 +355,31 @@ class ZypperTestCase(TestCase):
|
|||
self.assertTrue(pkgs.get(pkg_name))
|
||||
self.assertEqual(pkgs[pkg_name], pkg_version)
|
||||
|
||||
def test_download(self):
|
||||
'''
|
||||
Test package download
|
||||
:return:
|
||||
'''
|
||||
download_out = {
|
||||
'stdout': get_test_data('zypper-download.xml'),
|
||||
'stderr': None,
|
||||
'retcode': 0
|
||||
}
|
||||
|
||||
test_out = {
|
||||
'nmap': {
|
||||
'path': u'/var/cache/zypp/packages/SLE-12-x86_64-Pool/x86_64/nmap-6.46-1.72.x86_64.rpm',
|
||||
'repository-alias': u'SLE-12-x86_64-Pool',
|
||||
'repository-name': u'SLE-12-x86_64-Pool'
|
||||
}
|
||||
}
|
||||
|
||||
with patch.dict(zypper.__salt__, {'cmd.run_all': MagicMock(return_value=download_out)}):
|
||||
with patch.dict(zypper.__salt__, {'lowpkg.checksum': MagicMock(return_value=True)}):
|
||||
self.assertEqual(zypper.download("nmap"), test_out)
|
||||
test_out['_error'] = "The following package(s) failed to download: foo"
|
||||
self.assertEqual(zypper.download("nmap", "foo"), test_out)
|
||||
|
||||
def test_remove_purge(self):
|
||||
'''
|
||||
Test package removal
|
||||
|
|
Loading…
Add table
Reference in a new issue