Skip to content

Commit cfe14cb

Browse files
wagner-intevationwaldbauer-certat
authored andcommittedAug 3, 2022
tst: add tests for bot initialization regex
1 parent bbec481 commit cfe14cb

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed
 

‎CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ CHANGELOG
115115
- Add GitHub Action to run regexploit on all Python, JSON and YAML files (PR#2059 by Sebastian Wagner).
116116
- `intelmq.lib.test`:
117117
- Decorator `skip_ci` also detects `dpkg-buildpackage` environments by checking the environment variable `DEB_BUILD_ARCH` (PR#2123 by Sebastian Wagner).
118-
- Fixing regex to catchall after python version and process id (PR#2216 by Sebastian Waldbauer, fixes #2185)
118+
- Fixing regex to catchall after python version and process ID, add tests for it (PR#2216 by Sebastian Waldbauer and Sebastian Wagner, fixes #2185)
119119
- Also test on Python 3.10 (PR#2140 by Sebastian Wagner).
120120
- Switch from nosetests to pytest, as the former does not support Python 3.10 (PR#2140 by Sebastian Wagner).
121121
- CodeQL Github Actions `exponential backtracking on strings` fixed. (PR#2148 by Sebastian Waldbauer, fixes #2138)

‎intelmq/lib/test.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
"source_pipeline_broker": "pythonlist",
4545
"testing": True,
4646
}
47+
BOT_INIT_REGEX = ("{} initialized with id {} and"
48+
r" intelmq [0-9a-z.]*"
49+
r" and python [0-9a-z.]*"
50+
r" \(.*?\)([0-9a-zA-Z.\ \[\]]*)"
51+
r"as process [0-9]+\.")
4752

4853

4954
class Parameters:
@@ -349,13 +354,8 @@ def run_bot(self, iterations: int = 1, error_on_pipeline: bool = False,
349354
self.assertIn('raw', event)
350355

351356
""" Test if bot log messages are correctly formatted. """
352-
self.assertLoglineMatches(0, "{} initialized with id {} and"
353-
r" intelmq [0-9a-z.]*"
354-
r" and python [0-9a-z.]*"
355-
r" \(.*?\)([0-9a-zA-Z.\ \[\]]*)"
356-
r"as process [0-9]+\."
357-
"".format(self.bot_name,
358-
self.bot_id), "INFO")
357+
self.assertLoglineMatches(0, BOT_INIT_REGEX.format(self.bot_name,
358+
self.bot_id), "INFO")
359359
self.assertRegexpMatchesLog("INFO - Bot is starting.")
360360
if stop_bot:
361361
self.assertLoglineEqual(-1, "Bot stopped.", "INFO")

‎intelmq/tests/lib/test_test.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# SPDX-FileCopyrightText: 2022 Intevation GmbH
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
# -*- coding: utf-8 -*-
6+
7+
import unittest
8+
9+
from intelmq.lib.test import BOT_INIT_REGEX
10+
11+
12+
BOT_INIT_LINES = (
13+
# Ubuntu 22.04 https://github.com/certtools/intelmq/issues/2185
14+
'BOTNAME initialized with id BOTID and intelmq 3.0.2 and python 3.10.4 (main, Apr 2 2022, 09:04:19) [GCC 11.2.0] as process 10051.',
15+
)
16+
17+
18+
class TestBotTestCase(unittest.TestCase):
19+
def test_bot_init_regex(self):
20+
for line in BOT_INIT_LINES:
21+
self.assertRegex(line, BOT_INIT_REGEX.format('BOTNAME', 'BOTID'))
22+
23+
24+
if __name__ == '__main__': # pragma: no cover
25+
unittest.main()

0 commit comments

Comments
 (0)