]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1574] one more test under run_command
authorAndrei Pavel <andrei@isc.org>
Sun, 13 Dec 2020 16:50:36 +0000 (18:50 +0200)
committerAndrei Pavel <andrei@isc.org>
Mon, 14 Dec 2020 10:08:39 +0000 (12:08 +0200)
src/bin/shell/tests/basic_auth_tests.sh.in
src/lib/log/tests/init_logger_test.sh.in

index 138951e2c295acba4ca17cbf0d63b21258bab5e3..245900a15bb299b7965813e55970288495389b74 100644 (file)
@@ -68,6 +68,16 @@ tmpfile_path="@abs_top_builddir@/src/bin/shell/tests"
 # Import common test library.
 . "@abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh"
 
+run_kea_shell() {
+    # shellcheck disable=SC2086
+    # SC2086: Double quote to prevent globbing and word splitting.
+    # reason: ${auth} can be empty here, if we quote, it will be interpreted as
+    # an empty string which is not desired as it will result in unrecognized
+    # argument from kea-shell.
+    echo | "${shell_bin_path}/${shell_bin}" --host 127.0.0.1 --port 8081 \
+        ${auth} "${cmd}" > "${tmpfile_path}/shell-stdout.txt"
+}
+
 # This test verifies that Control Agent is shut down gracefully when it
 # receives a SIGINT or SIGTERM signal.
 shell_command_test() {
@@ -124,40 +134,31 @@ shell_command_test() {
  127.0.0.1 --port 8081 ${auth} ${cmd} > ${tmpfile_path}/shell-stdout.txt"
     echo "Executing kea-shell ($tmp)"
 
-    set +e
-    # shellcheck disable=SC2086
-    # SC2086: Double quote to prevent globbing and word splitting.
-    # reason: ${auth} can be empty here, if we quote, it will be interpreted as
-    # an empty string which is not desired as it will result in unrecognized
-    # argument from kea-shell.
-    echo | ${shell_bin_path}/${shell_bin} --host 127.0.0.1 \
- --port 8081 ${auth} "${cmd}" > ${tmpfile_path}/shell-stdout.txt
-    shell_exit_code=$?
-    set -e
+    run_command \
+        run_kea_shell
 
     # Check the exit code
     if [ "${exp_result}" = "fail" ]; then
-        if [ "${shell_exit_code}" -eq 0 ]; then
+        if [ "${EXIT_CODE}" -eq 0 ]; then
             echo "ERROR:" \
-            "kea-shell returned ${shell_exit_code} exit code, expected 1."
+            "kea-shell returned ${EXIT_CODE} exit code, expected 1."
         else
-            echo "kea-shell returned ${shell_exit_code} exit code as expected."
+            echo "kea-shell returned ${EXIT_CODE} exit code as expected."
         fi
-    elif [ "${shell_exit_code}" -ne 0 ]; then
+    elif [ "${EXIT_CODE}" -ne 0 ]; then
         echo "ERROR:" \
-        "kea-shell returned ${shell_exit_code} exit code, expected 0."
+        "kea-shell returned ${EXIT_CODE} exit code, expected 0."
     else
-        echo "kea-shell returned ${shell_exit_code} exit code as expected."
+        echo "kea-shell returned ${EXIT_CODE} exit code as expected."
     fi
 
     # Now check the response
     rm -f ${tmpfile_path}/shell-expected.txt
     printf '%s\n' "${exp_rsp}" > ${tmpfile_path}/shell-expected.txt
-    set +e
-    diff ${tmpfile_path}/shell-stdout.txt ${tmpfile_path}/shell-expected.txt
-    diff_code=$?
-    set -e
-    if [ "${diff_code}" -ne 0 ]; then
+    if diff "${tmpfile_path}/shell-stdout.txt" "${tmpfile_path}/shell-expected.txt"; then
+        echo "Content returned by kea-shell meets expectation."
+        rm ${tmpfile_path}/shell-*.txt
+    else
         echo "ERROR:" \
         "content returned is different than expected." \
         "See ${tmpfile_path}/shell-*.txt"
@@ -166,9 +167,6 @@ shell_command_test() {
         echo "ACTUAL RESULT:"
         cat ${tmpfile_path}/shell-stdout.txt
         clean_exit 1
-    else
-        echo "Content returned by kea-shell meets expectation."
-        rm ${tmpfile_path}/shell-*.txt
     fi
     # Main test phase ends.
 
index 14913734bad97a24e6433056a4b0183027ec82bb..37adaedfe53779f6a29ca205a9730acf2b9050aa 100644 (file)
@@ -35,7 +35,6 @@ passfail() {
 
 printf '1. Checking that KEA_LOGGER_SEVERITY/KEA_LOGGER_DBGLEVEL work\n'
 
-set +e
 printf '   - severity=DEBUG, dbglevel=99: '
 cat > $tempfile << .
 DEBUG [kea.log] LOG_BAD_DESTINATION unrecognized log destination: debug-0