[v2,01/18] tests: Add bash lib

Message ID 20240616160245.18865-2-jonatan.schlag@ipfire.org
State New
Headers
Series [v2,01/18] tests: Add bash lib |

Commit Message

Jonatan Schlag June 16, 2024, 4:02 p.m. UTC
  This allows use to write test with less effort as we can reuse functions

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
 tests/lib.sh | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 tests/lib.sh
  

Patch

diff --git a/tests/lib.sh b/tests/lib.sh
new file mode 100644
index 000000000..dd5e3f535
--- /dev/null
+++ b/tests/lib.sh
@@ -0,0 +1,27 @@ 
+#!/usr/bin/bash
+
+# Get the path of this file.
+# This ist rather complex as we do not want the calling script file
+# That why we use BASH_SOURCE[0]
+LIB_DIR="$(readlink -f "${BASH_SOURCE[0]}")"
+# In LIB_DIR is currently saved the path to this file you are currently reading
+# but we need the directory where it is located so:
+LIB_DIR="$(dirname "${LIB_DIR}")"
+
+
+. ${LIB_DIR}/lib_color.sh
+
+test_command() {
+
+	if ! "$@" ; then
+		echo -e "${CLR_RED_BG} Test failed: ${*} ${CLR_RESET}"
+		return 1
+	else
+		echo -e "${CLR_GREEN_BG} Test succeded: ${*} ${CLR_RESET}"
+		return 0
+	fi
+}
+
+var_has_value() {
+	[[ "${!1}" == "${2}" ]]
+}