aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2023-05-04 14:35:15 -0400
committerJake Hunsaker <jhunsake@redhat.com>2023-05-09 13:23:28 -0400
commitc59ab1c169098fd3a173a68e09373bdc2498139a (patch)
treed7a538d1509476c9bee4c6ea62c55dde217b6791 /tests
parent9f48da7aed9a2fa799becfdd0eec89d4458e0873 (diff)
downloadsos-c59ab1c169098fd3a173a68e09373bdc2498139a.tar.gz
[tests] Add tests for actual PackageManager implementations
Adds basic unit tests for the fitness of `PackageManager` implementations for rpm and dpkg, as well as the new `MultiPackageManager` using both of those. Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/policy_tests.py60
1 files changed, 59 insertions, 1 deletions
diff --git a/tests/unittests/policy_tests.py b/tests/unittests/policy_tests.py
index 81210815..ddd2f4b9 100644
--- a/tests/unittests/policy_tests.py
+++ b/tests/unittests/policy_tests.py
@@ -7,9 +7,13 @@
# See the LICENSE file in the source distribution for further information.
import unittest
+from avocado.utils import distro
+
from sos.policies import Policy, import_policy
from sos.policies.distros import LinuxPolicy
-from sos.policies.package_managers import PackageManager
+from sos.policies.package_managers import PackageManager, MultiPackageManager
+from sos.policies.package_managers.rpm import RpmPackageManager
+from sos.policies.package_managers.dpkg import DpkgPackageManager
from sos.report.plugins import (Plugin, IndependentPlugin,
RedHatPlugin, DebianPlugin)
@@ -97,6 +101,60 @@ class PackageManagerTests(unittest.TestCase):
self.assertEquals(self.pm.pkg_by_name('foo'), None)
+class RpmPackageManagerTests(unittest.TestCase):
+
+ def setUp(self):
+ if distro.detect().name not in ['fedora', 'centos', 'rhel']:
+ self.skipTest('Not running on an RPM distribution')
+ self.pm = RpmPackageManager()
+
+ def test_load_all_packages(self):
+ self.assertNotEquals(self.pm.packages, {})
+
+ def test_pkg_is_formatted(self):
+ kpkg = self.pm.pkg_by_name('coreutils')
+ self.assertIsInstance(kpkg, dict)
+ self.assertIsInstance(kpkg['version'], list)
+ self.assertEquals(kpkg['pkg_manager'], 'rpm')
+
+
+class DpkgPackageManagerTests(unittest.TestCase):
+
+ def setUp(self):
+ if distro.detect().name not in ['Ubuntu', 'debian']:
+ self.skipTest('Not running on a dpkg distribution')
+ self.pm = DpkgPackageManager()
+
+ def test_load_all_packages(self):
+ self.assertNotEquals(self.pm.packages, {})
+
+ def test_pkg_is_formatted(self):
+ kpkg = self.pm.pkg_by_name('coreutils')
+ self.assertIsInstance(kpkg, dict)
+ self.assertIsInstance(kpkg['version'], list)
+ self.assertEquals(kpkg['pkg_manager'], 'dpkg')
+
+
+class MultiPackageManagerTests(unittest.TestCase):
+
+ def setUp(self):
+ self.pm = MultiPackageManager(primary=RpmPackageManager,
+ fallbacks=[DpkgPackageManager])
+
+ def test_load_all_packages(self):
+ self.assertNotEquals(self.pm.packages, {})
+
+ def test_pkg_is_formatted(self):
+ kpkg = self.pm.pkg_by_name('coreutils')
+ self.assertIsInstance(kpkg, dict)
+ self.assertIsInstance(kpkg['version'], list)
+ _local = distro.detect().name
+ if _local in ['Ubuntu', 'debian']:
+ self.assertEquals(kpkg['pkg_manager'], 'dpkg')
+ else:
+ self.assertEquals(kpkg['pkg_manager'], 'rpm')
+
+
if __name__ == "__main__":
unittest.main()