]> source.dussan.org Git - rspamd.git/commitdiff
[Test] Some more tests for logging 4767/head
authorAndrew Lewis <nerf@judo.za.org>
Mon, 1 Jan 2024 14:01:50 +0000 (16:01 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Mon, 1 Jan 2024 14:01:50 +0000 (16:01 +0200)
test/functional/cases/410_logging/000_console/000_systemd_logger.robot [new file with mode: 0644]
test/functional/cases/410_logging/000_console/001_timestamps.robot [new file with mode: 0644]
test/functional/cases/410_logging/001_file/000_json.robot [new file with mode: 0644]
test/functional/cases/410_systemd_logger.robot [deleted file]
test/functional/configs/loggingtest-local.conf [new file with mode: 0644]
test/functional/configs/loggingtest.conf [new file with mode: 0644]
test/functional/configs/systemd-local.conf [deleted file]
test/functional/configs/systemd.conf [deleted file]
test/functional/lib/rspamd.py

diff --git a/test/functional/cases/410_logging/000_console/000_systemd_logger.robot b/test/functional/cases/410_logging/000_console/000_systemd_logger.robot
new file mode 100644 (file)
index 0000000..8817846
--- /dev/null
@@ -0,0 +1,24 @@
+*** Settings ***
+Suite Setup     Rspamd Setup
+Suite Teardown  Systemd Teardown
+Library         ${RSPAMD_TESTDIR}/lib/rspamd.py
+Resource        ${RSPAMD_TESTDIR}/lib/rspamd.robot
+Variables       ${RSPAMD_TESTDIR}/lib/vars.py
+
+*** Variables ***
+${CONFIG}                         ${RSPAMD_TESTDIR}/configs/loggingtest.conf
+${RSPAMD_LOGGINGTYPE}             console
+${RSPAMD_JSON}                    false
+${RSPAMD_SYSTEMD}                 true
+${RSPAMD_SCOPE}                   Suite
+
+*** Test Cases ***
+EMPTY TEST
+  Pass Execution  No worries
+
+*** Keywords ***
+Systemd Teardown
+  Touch  ${RSPAMD_TMPDIR}/rspamd.log
+  Rspamd Teardown
+  ${log} =  Get File  ${EXECDIR}/robot-save/rspamd.stderr.last
+  Should Match Regexp  ${log}  \\n\\(main\\) lua; lua_cfg_transform\\.lua:\\d+: overriding actions from the legacy metric settings\\n
diff --git a/test/functional/cases/410_logging/000_console/001_timestamps.robot b/test/functional/cases/410_logging/000_console/001_timestamps.robot
new file mode 100644 (file)
index 0000000..bd8e2c3
--- /dev/null
@@ -0,0 +1,24 @@
+*** Settings ***
+Suite Setup     Rspamd Setup
+Suite Teardown  Console Timestamps Teardown
+Library         ${RSPAMD_TESTDIR}/lib/rspamd.py
+Resource        ${RSPAMD_TESTDIR}/lib/rspamd.robot
+Variables       ${RSPAMD_TESTDIR}/lib/vars.py
+
+*** Variables ***
+${CONFIG}                         ${RSPAMD_TESTDIR}/configs/loggingtest.conf
+${RSPAMD_LOGGINGTYPE}             console
+${RSPAMD_JSON}                    false
+${RSPAMD_SYSTEMD}                 false
+${RSPAMD_SCOPE}                   Suite
+
+*** Test Cases ***
+EMPTY TEST
+  Pass Execution  No worries
+
+*** Keywords ***
+Console Timestamps Teardown
+  Touch  ${RSPAMD_TMPDIR}/rspamd.log
+  Rspamd Teardown
+  ${log} =  Get File  ${EXECDIR}/robot-save/rspamd.stderr.last
+  Should Match Regexp  ${log}  \\n\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}  #\\d+\\(main\\) lua; lua_cfg_transform\\.lua:\\d+: overriding actions from the legacy metric settings\\n
diff --git a/test/functional/cases/410_logging/001_file/000_json.robot b/test/functional/cases/410_logging/001_file/000_json.robot
new file mode 100644 (file)
index 0000000..a2f04e8
--- /dev/null
@@ -0,0 +1,17 @@
+*** Settings ***
+Test Setup      Rspamd Setup
+Library         ${RSPAMD_TESTDIR}/lib/rspamd.py
+Resource        ${RSPAMD_TESTDIR}/lib/rspamd.robot
+Variables       ${RSPAMD_TESTDIR}/lib/vars.py
+
+*** Variables ***
+${CONFIG}                         ${RSPAMD_TESTDIR}/configs/loggingtest.conf
+${RSPAMD_LOGGINGTYPE}             file
+${RSPAMD_JSON}                    true
+${RSPAMD_SYSTEMD}                 true
+${RSPAMD_SCOPE}                   Test
+
+*** Test Cases ***
+JSON LOGS
+  Rspamd Teardown
+  Check JSON Log  ${EXECDIR}/robot-save/rspamd.log.last
diff --git a/test/functional/cases/410_systemd_logger.robot b/test/functional/cases/410_systemd_logger.robot
deleted file mode 100644 (file)
index f90d160..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-*** Settings ***
-Suite Setup     Rspamd Setup
-Suite Teardown  Systemd Teardown
-Library         ${RSPAMD_TESTDIR}/lib/rspamd.py
-Resource        ${RSPAMD_TESTDIR}/lib/rspamd.robot
-Variables       ${RSPAMD_TESTDIR}/lib/vars.py
-
-*** Variables ***
-${CONFIG}                         ${RSPAMD_TESTDIR}/configs/systemd.conf
-${RSPAMD_SCOPE}                   Suite
-
-*** Test Cases ***
-EMPTY TEST
-  Pass Execution  No worries
-
-*** Keywords ***
-Systemd Teardown
-  Touch  ${RSPAMD_TMPDIR}/rspamd.log
-  Rspamd Teardown
-  ${log} =  Get File  ${EXECDIR}/robot-save/rspamd.stderr.last
-  Should Match Regexp  ${log}  \\n\\(main\\) lua; lua_cfg_transform\\.lua:\\d+: overriding actions from the legacy metric settings\\n
diff --git a/test/functional/configs/loggingtest-local.conf b/test/functional/configs/loggingtest-local.conf
new file mode 100644 (file)
index 0000000..7330d97
--- /dev/null
@@ -0,0 +1,5 @@
+logging {
+  type = "{= env.LOGGINGTYPE =}";
+  json = {= env.JSON =};
+  systemd = {= env.SYSTEMD =};
+}
diff --git a/test/functional/configs/loggingtest.conf b/test/functional/configs/loggingtest.conf
new file mode 100644 (file)
index 0000000..99026df
--- /dev/null
@@ -0,0 +1,3 @@
+.include(duplicate=append,priority=0) "{= env.TESTDIR =}/configs/trivial.conf"
+
+.include(priority=1,duplicate=merge) "{= env.TESTDIR =}/configs/loggingtest-local.conf"
diff --git a/test/functional/configs/systemd-local.conf b/test/functional/configs/systemd-local.conf
deleted file mode 100644 (file)
index ed796a9..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-logging {
-  type = "console";
-  systemd = true;
-}
diff --git a/test/functional/configs/systemd.conf b/test/functional/configs/systemd.conf
deleted file mode 100644 (file)
index f57827c..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-.include(duplicate=append,priority=0) "{= env.TESTDIR =}/configs/trivial.conf"
-
-.include(priority=1,duplicate=merge) "{= env.TESTDIR =}/configs/systemd-local.conf"
index 49c21a449b8af02ad27bdc9e50396007d5f636e3..3976ca9490c39d0cad5242159e1f04964f6f267a 100644 (file)
@@ -24,6 +24,15 @@ def Check_JSON(j):
     assert 'error' not in d
     return d
 
+def check_json_log(fn):
+    line_count = 0
+    f = open(fn, 'r')
+    for l in f.readlines():
+        d = demjson.decode(l, strict=True)
+        assert len(d) > 0
+        line_count = line_count + 1
+    assert line_count > 0
+
 def cleanup_temporary_directory(directory):
     shutil.rmtree(directory)