]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4159] Add unit tests
authorAndrei Pavel <andrei@isc.org>
Tue, 11 Nov 2025 08:50:22 +0000 (10:50 +0200)
committerAndrei Pavel <andrei@isc.org>
Tue, 11 Nov 2025 09:07:58 +0000 (11:07 +0200)
src/bin/admin/tests/admin_tests.sh.in
src/bin/admin/tests/meson.build
src/bin/lfc/tests/lfc_process_tests.sh.in [new file with mode: 0755]
src/bin/lfc/tests/meson.build
src/bin/perfdhcp/tests/meson.build
src/bin/perfdhcp/tests/perfdhcp_process_tests.sh.in [new file with mode: 0755]
src/bin/shell/tests/meson.build
src/bin/shell/tests/shell_process_tests.sh.in [new file with mode: 0755]
src/lib/process/cfgrpt/tests/config_report_unittests.cc
src/lib/testutils/dhcp_test_lib.sh.in
src/lib/testutils/meson.build

index 4b59c9505981ed92f60a06217b7ead5c51084b6d..c928606a6946cb7811a3f823a4ba23f51c75969c 100755 (executable)
@@ -140,6 +140,20 @@ kea_admin_error_reporting_tests() {
   assert_eq 1 "${EXIT_CODE}"
   assert_str_eq 'ERROR/kea-admin: -x or --extra requires a parameter' "$(printf '%s\n' "${OUTPUT}" | head -n 1)"
   test_finish ${?}
+
+  test_start 'kea_admin_version.version'
+  run_command \
+    "${kea_admin}" -v
+  assert_eq 0 "${EXIT_CODE}"
+  assert_str_eq '@version@' "$(printf '%s\n' "${OUTPUT}" | head -n 1)"
+  test_finish ${?}
+
+  test_start 'kea_admin_version.extended_version'
+  run_command \
+    "${kea_admin}" -V
+  assert_eq 0 "${EXIT_CODE}"
+  assert_str_eq '@extended_version@' "$(printf '%s\n' "${OUTPUT}" | head -n 1)"
+  test_finish ${?}
 }
 
 # Run tests.
index adfc32831f1658e01b338ba9c76eb9b3e79db36f..2a4af41c00b44d5a7dc9b18ee24dff268657e905 100644 (file)
@@ -5,6 +5,8 @@ endif
 kea_admin_tests_conf_data = configuration_data()
 kea_admin_tests_conf_data.set('abs_top_builddir', TOP_BUILD_DIR)
 kea_admin_tests_conf_data.set('abs_top_srcdir', TOP_SOURCE_DIR)
+kea_admin_tests_conf_data.set('version', PROJECT_VERSION)
+kea_admin_tests_conf_data.set('extended_version', EXTENDED_VERSION)
 admin_tests = configure_file(
     input: 'admin_tests.sh.in',
     output: 'admin_tests.sh',
diff --git a/src/bin/lfc/tests/lfc_process_tests.sh.in b/src/bin/lfc/tests/lfc_process_tests.sh.in
new file mode 100755 (executable)
index 0000000..d3b8ea2
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+# Copyright (C) 2025 Internet Systems Consortium, Inc. ("ISC")
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Exit with error if commands exit with non-zero and if undefined variables are
+# used.
+set -eu
+
+# Set the location of the executable.
+bin='kea-lfc'
+bin_path='@abs_top_builddir@/src/bin/lfc'
+
+# Import common test library.
+# shellcheck source=src/lib/testutils/dhcp_test_lib.sh.in
+. '@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh'
+
+version_test "lfc.version"
index 59692ce1a43fac60dc8df962867428730b6fc2ea..d096cdee7ce3e93d21005b5c64d1e3f070e76f21 100644 (file)
@@ -22,3 +22,19 @@ test(
     depends: [kea_lfc],
     protocol: 'gtest',
 )
+
+lfc_tests_conf_data = configuration_data()
+lfc_tests_conf_data.set('abs_top_builddir', TOP_BUILD_DIR)
+lfc_process_tests = configure_file(
+    input: 'lfc_process_tests.sh.in',
+    output: 'lfc_process_tests.sh',
+    configuration: lfc_tests_conf_data,
+)
+test(
+    'lfc_process_tests.sh',
+    lfc_process_tests,
+    workdir: current_build_dir,
+    is_parallel: false,
+    priority: -1,
+    suite: 'shell-tests',
+)
index ba08ef865c48d07f39555d62eca95a680aedef19..b0d50496df1b6654dc78f2622f03560ea19eabe0 100644 (file)
@@ -30,3 +30,19 @@ test(
     is_parallel: false,
     priority: -1,
 )
+
+perfdhcp_tests_conf_data = configuration_data()
+perfdhcp_tests_conf_data.set('abs_top_builddir', TOP_BUILD_DIR)
+perfdhcp_process_tests = configure_file(
+    input: 'perfdhcp_process_tests.sh.in',
+    output: 'perfdhcp_process_tests.sh',
+    configuration: perfdhcp_tests_conf_data,
+)
+test(
+    'perfdhcp_process_tests.sh',
+    perfdhcp_process_tests,
+    workdir: current_build_dir,
+    is_parallel: false,
+    priority: -1,
+    suite: 'shell-tests',
+)
diff --git a/src/bin/perfdhcp/tests/perfdhcp_process_tests.sh.in b/src/bin/perfdhcp/tests/perfdhcp_process_tests.sh.in
new file mode 100755 (executable)
index 0000000..110668b
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+# Copyright (C) 2025 Internet Systems Consortium, Inc. ("ISC")
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Exit with error if commands exit with non-zero and if undefined variables are
+# used.
+set -eu
+
+# Set the location of the executable.
+bin='perfdhcp'
+bin_path='@abs_top_builddir@/src/bin/perfdhcp'
+
+# Import common test library.
+# shellcheck source=src/lib/testutils/dhcp_test_lib.sh.in
+. '@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh'
+
+version_test "perfdhcp.version"
index 18a7bc3339be7e514ec2de28b1dfdf051b70740d..3ead8123fa85d9159b26de0e5c2193682edba5a1 100644 (file)
@@ -165,6 +165,19 @@ test(
     priority: -1,
     suite: 'shell-tests',
 )
+shell_process_tests = configure_file(
+    input: 'shell_process_tests.sh.in',
+    output: 'shell_process_tests.sh',
+    configuration: shell_tests_conf_data,
+)
+test(
+    'shell_process_tests.sh',
+    shell_process_tests,
+    workdir: current_build_dir,
+    is_parallel: false,
+    priority: -1,
+    suite: 'shell-tests',
+)
 auth_bad_password_file = configure_file(
     input: 'auth_bad_password_file.in',
     output: 'auth_bad_password_file',
diff --git a/src/bin/shell/tests/shell_process_tests.sh.in b/src/bin/shell/tests/shell_process_tests.sh.in
new file mode 100755 (executable)
index 0000000..6deb8aa
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+# Copyright (C) 2025 Internet Systems Consortium, Inc. ("ISC")
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Exit with error if commands exit with non-zero and if undefined variables are
+# used.
+set -eu
+
+# Set the location of the executable.
+bin='kea-shell'
+bin_path='@abs_top_builddir@/src/bin/shell'
+
+# Import common test library.
+# shellcheck source=src/lib/testutils/dhcp_test_lib.sh.in
+. '@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh'
+
+version_test "shell.version"
index c83360d9867306fdb408edcc383ad37a59dabe29..2564d64397633a4f3e1fa160e60cb1d444360790 100644 (file)
@@ -26,6 +26,7 @@ TEST(ConfigReportTest, getConfigReport) {
     ASSERT_FALSE(cfgReport.empty());
     EXPECT_NE(std::string::npos, cfgReport.find(VERSION));
     EXPECT_NE(std::string::npos, cfgReport.find(EXTENDED_VERSION));
+    EXPECT_NE(std::string::npos, cfgReport.find(SOURCE_OF_INSTALLATION));
     EXPECT_NE(std::string::npos, cfgReport.find(std::string("Hooks directory:    ") +
                                                 HooksLibrariesParser::getHooksPath()));
 }
index 13565bd03fdc1971201f82121d6e29012870e03a..15c5e86917efc4b9594724ea67310383a2a2b315 100755 (executable)
@@ -26,7 +26,8 @@ set -eu
 prefix="@prefix@"
 
 # Expected version
-EXPECTED_VERSION="@PACKAGE_VERSION@"
+VERSION='@VERSION@'
+EXTENDED_VERSION='@EXTENDED_VERSION@'
 
 # Kea environment variables for shell tests.
 # KEA_LOGGER_DESTINATION is set per test with set_logger.
@@ -935,13 +936,33 @@ version_test() {
         run_command \
             "${bin_path}/${bin}" "${v}"
 
-        if test "${OUTPUT}" != "${EXPECTED_VERSION}"; then
+        if test 0 -ne "${EXIT_CODE}"; then
+            printf 'ERROR: Expected exit code 0, got "%s" when calling "%s"\n' \
+                "${EXIT_CODE}" "${bin} -V"
+            clean_exit 1
+        fi
+
+        if test "${OUTPUT}" != "${VERSION}"; then
             printf 'ERROR: Expected version "%s", got "%s" when calling "%s"\n' \
-                "${EXPECTED_VERSION}" "${OUTPUT}" "${bin} ${v}"
+                "${VERSION}" "${OUTPUT}" "${bin} ${v}"
             test_finish 1
         fi
     done
 
+    # Check -V.
+    run_command \
+        "${bin_path}/${bin}" -V
+    if test 0 -ne "${EXIT_CODE}"; then
+        printf 'ERROR: Expected exit code 0, got "%s" when calling "%s"\n' \
+            "${EXIT_CODE}" "${bin} -V"
+        clean_exit 1
+    fi
+    if test "${EXTENDED_VERSION}" != "$(echo "${OUTPUT}" | head -n 1)"; then
+        printf 'ERROR: Expected version "%s", got "%s" when calling "%s"\n' \
+            "${EXTENDED_VERSION}" "${OUTPUT}" "${bin} -V"
+        clean_exit 1
+    fi
+
     test_finish 0
 }
 
@@ -1080,10 +1101,10 @@ server_pid_file_test() {
 }
 
 # This test verifies that passwords are redacted in logs.
-# This function takes 2 parameters:
-# test_name
-# config - string with a content of the config (will be written to a file)
-# expected_code - expected exit code returned by kea (0 - success, 1 - failure)
+# This function takes 3 parameters:
+# test_name
+# config - string with a content of the config (will be written to a file)
+# expected_code - expected exit code returned by kea (0 - success, 1 - failure)
 password_redact_test() {
     local test_name="${1}"
     local config="${2}"
index 11de1d46a04396fbc84d47ab34e2d118a0373c46..f3cf9f431b734779af754c63ea1287ce2281202d 100644 (file)
@@ -18,7 +18,8 @@ kea_testutils_lib = static_library(
 dhcp_test_lib_conf_data = configuration_data()
 dhcp_test_lib_conf_data.set('abs_top_builddir', TOP_BUILD_DIR)
 dhcp_test_lib_conf_data.set('prefix', PREFIX)
-dhcp_test_lib_conf_data.set('PACKAGE_VERSION', PROJECT_VERSION)
+dhcp_test_lib_conf_data.set('VERSION', PROJECT_VERSION)
+dhcp_test_lib_conf_data.set('EXTENDED_VERSION', EXTENDED_VERSION)
 configure_file(
     input: 'dhcp_test_lib.sh.in',
     output: 'dhcp_test_lib.sh',