From c78c4a150405effb7a0d35952a2f71ed51ddc21b Mon Sep 17 00:00:00 2001 From: David Negreira Date: Fri, 13 Sep 2024 13:17:27 +0000 Subject: [PATCH] Improve apt.test_provides unit test The unit test was failing on recent versions of Debian and Ubuntu because the `login` package is no longer installing the binary on `/bin/login` but rather on `/usr/bin/login`. We have added a function which will retrieve the binary path depending on the distro as well. Resolves: #6028 Signed-off-by: David Negreira --- selftests/unit/utils/software_manager.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/selftests/unit/utils/software_manager.py b/selftests/unit/utils/software_manager.py index e034b05ec7..7b21e60e16 100644 --- a/selftests/unit/utils/software_manager.py +++ b/selftests/unit/utils/software_manager.py @@ -13,12 +13,26 @@ def apt_supported_distro(): return distro.detect().name in ["debian", "Ubuntu"] +def login_binary_path(distro_name, distro_version): + """Retrieve the login binary path based on the distro version"""" + if distro_name == "Ubuntu": + if float(distro_version) >= 24.04: + return "/usr/bin/login" + if distro_name == "debian": + if distro_version == "trixie": + return "/usr/bin/login" + return "/bin/login" + + @unittest.skipUnless(os.getuid() == 0, "This test requires root privileges") @unittest.skipUnless(apt_supported_distro(), "Unsupported distro") class Apt(unittest.TestCase): def test_provides(self): sm = manager.SoftwareManager() - self.assertEqual(sm.provides("/bin/login"), "login") + distro_name = distro.detect().name + distro_version = distro.detect().version + login_path = login_binary_path(distro_name, distro_version) + self.assertEqual(sm.provides(login_path), "login") self.assertTrue(isinstance(sm.backend, backends.apt.AptBackend))