diff options
author | Benjamin Drung <bdrung@debian.org> | 2023-06-10 08:55:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-06-10 09:21:49 +0000 |
commit | 88837172f69eabc408ae3945d82e0270b8e07440 (patch) | |
tree | d6b7fa06694f45d25f54f6ea9ded93c981e51f6f /test/test-avahi.py | |
parent | Initial commit. (diff) | |
download | nvme-stas-88837172f69eabc408ae3945d82e0270b8e07440.tar.xz nvme-stas-88837172f69eabc408ae3945d82e0270b8e07440.zip |
Adding upstream version 2.2.1.upstream/2.2.1
Signed-off-by: Benjamin Drung <bdrung@debian.org>
Diffstat (limited to 'test/test-avahi.py')
-rwxr-xr-x | test/test-avahi.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/test-avahi.py b/test/test-avahi.py new file mode 100755 index 0000000..3529104 --- /dev/null +++ b/test/test-avahi.py @@ -0,0 +1,41 @@ +#!/usr/bin/python3 +import shutil +import logging +import unittest +from staslib import avahi +import dasbus.connection +import subprocess + +SYSTEMCTL = shutil.which('systemctl') + + +class Test(unittest.TestCase): + '''Unit tests for class Avahi''' + + def test_new(self): + sysbus = dasbus.connection.SystemMessageBus() + srv = avahi.Avahi(sysbus, lambda: "ok") + self.assertEqual(srv.info(), {'avahi wake up timer': '60.0s [off]', 'service types': [], 'services': {}}) + self.assertEqual(srv.get_controllers(), []) + + try: + # Check that the Avahi daemon is running + subprocess.run([SYSTEMCTL, 'is-active', 'avahi-daemon.service'], check=True) + self.assertFalse(srv._on_kick_avahi()) + except subprocess.CalledProcessError: + self.assertTrue(srv._on_kick_avahi()) + + with self.assertLogs(logger=logging.getLogger(), level='INFO') as captured: + srv._avahi_available(None) + self.assertEqual(len(captured.records), 1) + self.assertEqual(captured.records[0].getMessage(), "avahi-daemon service available, zeroconf supported.") + with self.assertLogs(logger=logging.getLogger(), level='WARN') as captured: + srv._avahi_unavailable(None) + self.assertEqual(len(captured.records), 1) + self.assertEqual(captured.records[0].getMessage(), "avahi-daemon not available, zeroconf not supported.") + srv.kill() + self.assertEqual(srv.info(), {'avahi wake up timer': 'None', 'service types': [], 'services': {}}) + + +if __name__ == '__main__': + unittest.main() |