Skip to content

Commit

Permalink
Improve apt.test_provides unit test
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dnegreira committed Sep 13, 2024
1 parent a44d5ab commit eff2add
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion selftests/unit/utils/software_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand Down

0 comments on commit eff2add

Please sign in to comment.