SHA256
1
0
forked from pool/salt
salt/0010-unit-tests-for-rpm.checksum-and-zypper.download.patch

106 lines
4.1 KiB
Diff

From 2742ee76ccc50cd4f84e44861ef82ec5f3b5234a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?=
<psuarezhernandez@suse.com>
Date: Wed, 25 May 2016 17:08:16 +0100
Subject: [PATCH 10/11] unit tests for rpm.checksum() and zypper.download()
lint issue fixed
---
tests/unit/modules/rpm_test.py | 16 ++++++++++++++++
tests/unit/modules/zypp/zypper-download.xml | 19 +++++++++++++++++++
tests/unit/modules/zypper_test.py | 25 +++++++++++++++++++++++++
3 files changed, 60 insertions(+)
create mode 100644 tests/unit/modules/zypp/zypper-download.xml
diff --git a/tests/unit/modules/rpm_test.py b/tests/unit/modules/rpm_test.py
index f180736..4042137 100644
--- a/tests/unit/modules/rpm_test.py
+++ b/tests/unit/modules/rpm_test.py
@@ -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):
'''
diff --git a/tests/unit/modules/zypp/zypper-download.xml b/tests/unit/modules/zypp/zypper-download.xml
new file mode 100644
index 0000000..eeea0a5
--- /dev/null
+++ b/tests/unit/modules/zypp/zypper-download.xml
@@ -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>
diff --git a/tests/unit/modules/zypper_test.py b/tests/unit/modules/zypper_test.py
index 4e735cd..9ec2b83 100644
--- a/tests/unit/modules/zypper_test.py
+++ b/tests/unit/modules/zypper_test.py
@@ -354,6 +354,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
--
2.8.2