]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add regression tests for structured logging
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 30 Dec 2025 14:55:05 +0000 (15:55 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 19 Jan 2026 10:01:29 +0000 (11:01 +0100)
Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
regression-tests.dnsdist/dnsdisttests.py
regression-tests.dnsdist/test_StructuredLogging.py [new file with mode: 0644]

index a00368c5f5628d82f3c1a6e7f0b8deb70f50e5d9..400eb92e3159b94b00b65876e914971921542f7a 100644 (file)
@@ -95,6 +95,7 @@ class DNSDistTest(AssertEqualDNSMessageMixin, unittest.TestCase):
     _healthCheckCounter = 0
     _answerUnexpected = True
     _checkConfigExpectedOutput = None
+    _checkConfigExpectedOutputPrefix = None
     _verboseMode = False
     _sudoMode = False
     _skipListeningOnCL = False
@@ -198,12 +199,18 @@ class DNSDistTest(AssertEqualDNSMessageMixin, unittest.TestCase):
             output = subprocess.check_output(testcmd, stderr=subprocess.STDOUT, close_fds=True)
         except subprocess.CalledProcessError as exc:
             raise AssertionError('dnsdist --check-config failed (%d): %s' % (exc.returncode, exc.output))
-        if cls._checkConfigExpectedOutput is not None:
-          expectedOutput = cls._checkConfigExpectedOutput
+
+        if cls._checkConfigExpectedOutputPrefix is not None:
+            if not output.startswith(cls._checkConfigExpectedOutputPrefix):
+                raise AssertionError('dnsdist --check-config failed: %s (expected prefix %s)' % (output, cls._checkConfigExpectedOutputPrefix))
         else:
-          expectedOutput = ('Configuration \'%s\' OK!\n' % (confFile)).encode()
-        if not cls._verboseMode and output != expectedOutput:
-            raise AssertionError('dnsdist --check-config failed: %s (expected %s)' % (output, expectedOutput))
+            if cls._checkConfigExpectedOutput is not None:
+                expectedOutput = cls._checkConfigExpectedOutput
+            else:
+                expectedOutput = ('Configuration \'%s\' OK!\n' % (confFile)).encode()
+
+            if not cls._verboseMode and output != expectedOutput:
+                raise AssertionError('dnsdist --check-config failed: %s (expected %s)' % (output, expectedOutput))
 
         logFile = os.path.join('configs', 'dnsdist_%s.log' % (cls.__name__))
         with open(logFile, 'w') as fdLog:
diff --git a/regression-tests.dnsdist/test_StructuredLogging.py b/regression-tests.dnsdist/test_StructuredLogging.py
new file mode 100644 (file)
index 0000000..9c9c6f7
--- /dev/null
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+from dnsdisttests import DNSDistTest, pickAvailablePort
+
+class TestStructuredLoggingDefaultBackendFromYaml(DNSDistTest):
+
+    _yaml_config_template = """---
+binds:
+  - listen_address: "127.0.0.1:%d"
+    protocol: Do53
+
+backends:
+  - address: "127.0.0.1:%d"
+    protocol: Do53
+
+logging:
+  structured:
+    enabled: true
+"""
+    _dnsDistPort = pickAvailablePort()
+    _testServerPort = pickAvailablePort()
+    _yaml_config_params = ['_dnsDistPort', '_testServerPort']
+    _config_params = []
+    _checkConfigExpectedOutput = None
+    _checkConfigExpectedOutputPrefix = b'msg="Configuration OK" subsystem="setup"'
+
+    def testOK(self):
+        pass
+
+class TestStructuredLoggingJSONBackendFromYaml(DNSDistTest):
+
+    _yaml_config_template = """---
+binds:
+  - listen_address: "127.0.0.1:%d"
+    protocol: Do53
+
+backends:
+  - address: "127.0.0.1:%d"
+    protocol: Do53
+
+logging:
+  structured:
+    enabled: true
+    backend: "json"
+"""
+    _dnsDistPort = pickAvailablePort()
+    _testServerPort = pickAvailablePort()
+    _yaml_config_params = ['_dnsDistPort', '_testServerPort']
+    _config_params = []
+    _checkConfigExpectedOutput = None
+    _checkConfigExpectedOutputPrefix = b'{"level": "0", "msg": "Configuration OK", "path":'
+
+    def testOK(self):
+        pass
+
+class TestStructuredLoggingDefaultBackendFromLua(DNSDistTest):
+
+    _config_template = """
+setStructuredLogging(true)
+
+newServer{address="127.0.0.1:%d"}
+"""
+    _testServerPort = pickAvailablePort()
+    _checkConfigExpectedOutput = None
+    _checkConfigExpectedOutputPrefix = b'msg="Configuration OK" subsystem="setup"'
+
+    def testOK(self):
+        pass
+
+class TestStructuredLoggingJSONBackendFromLua(DNSDistTest):
+
+    _config_template = """
+setStructuredLogging(true, {backend="json"})
+
+newServer{address="127.0.0.1:%d"}
+"""
+    _testServerPort = pickAvailablePort()
+    _checkConfigExpectedOutput = None
+    _checkConfigExpectedOutputPrefix = b'{"level": "0", "msg": "Configuration OK", "path":'
+
+    def testOK(self):
+        pass