From 5a2fd9b31ce0288e6e4e3894850f4235c71b9ef4 Mon Sep 17 00:00:00 2001 From: sebres Date: Sun, 30 Mar 2025 20:13:39 +0200 Subject: [PATCH] split new test to 2 tests (allows to cover `_globJournalFiles` even if system-journal is not available) --- fail2ban/tests/filtertestcase.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/fail2ban/tests/filtertestcase.py b/fail2ban/tests/filtertestcase.py index b03e1975..021d0dd3 100644 --- a/fail2ban/tests/filtertestcase.py +++ b/fail2ban/tests/filtertestcase.py @@ -32,7 +32,7 @@ import tempfile import uuid try: - from systemd import journal + from ..server.filtersystemd import journal, _globJournalFiles except ImportError: journal = None @@ -1510,11 +1510,8 @@ def get_monitor_failures_journal_testcase(Filter_): # pragma: systemd no cover return MonitorJournalFailures._runtimeJournal raise unittest.SkipTest('systemd journal seems to be not available (e. g. no rights to read)') - @with_tmpdir - def testGlobJournal(self, tmp): - try: - from ..server.filtersystemd import journal, _globJournalFiles - except ImportError: # pragma: no cover + def testGlobJournal_System(self): + if not journal: # pragma: no cover raise unittest.SkipTest("systemd python interface not available") jrnlfile = self._getRuntimeJournal() jrnlpath = os.path.dirname(jrnlfile) @@ -1522,6 +1519,11 @@ def get_monitor_failures_journal_testcase(Filter_): # pragma: systemd no cover self.assertIn(jrnlfile, _globJournalFiles(journal.SYSTEM_ONLY, jrnlpath)) self.assertIn(jrnlfile, _globJournalFiles(journal.LOCAL_ONLY)) self.assertIn(jrnlfile, _globJournalFiles(journal.LOCAL_ONLY, jrnlpath)) + + @with_tmpdir + def testGlobJournal(self, tmp): + if not journal: # pragma: no cover + raise unittest.SkipTest("systemd python interface not available") # no files yet in temp-path: self.assertFalse(_globJournalFiles(None, tmp)) # test against temp-path, shall ignore all rotated files: