[05/21] tests/lib.sh: Add logging functions
 
Commit Message
  
  
So we can change the style of our log messages better.
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
 tests/lib.sh | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
  
 
  
@@ -4,13 +4,21 @@  LIB_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
 
 . ${LIB_DIR}/lib_color.sh
 
+log_test_failed(){
+	echo -e "${CLR_RED_BG}Test failed: ${*}${CLR_RESET}'"
+}
+
+log_test_succeded(){
+	echo -e "${CLR_GREEN_BG}Test succeded: ${*}${CLR_RESET}"
+}
+
 test_that() {
 
 	if ! "$@" ; then
-		echo -e "${CLR_RED_BG} Test failed: ${*} ${CLR_RESET}"
+		log_test_failed "${*}"
 		return 1
 	else
-		echo -e "${CLR_GREEN_BG} Test succeded: ${*} ${CLR_RESET}"
+		log_test_succeded "${*}"
 		return 0
 	fi
 }
@@ -25,15 +33,15 @@  test_that_key_in_arry_has_value() {
 	local value="${3}"
 
 	if [[ ! -v "${array}" ]]; then
-		echo -e "${CLR_RED_BG}Test failed: The array '${1}' does not exists. The variable is not set.${CLR_RESET}'"
+		log_test_failed "The array '${1}' does not exists. The variable is not set."
 		return 1
 	fi
 
 	if [[ "${array[${key}]}" == "${value}" ]] ; then
-		echo -e "${CLR_GREEN_BG}Test succeded: The array '${1}' contains the value '${value}' under the key '${key}' ${CLR_RESET}"
+		log_test_succeded "The array '${1}' contains the value '${value}' under the key '${key}'"
 		return 0
 	else
-		echo -e "${CLR_RED_BG}Test failed: The array '${1}' contains the value '${array[${key}]}' under the key '${key} and not '${value}' ${CLR_RESET}"
+		log_test_failed "The array '${1}' contains the value '${array[${key}]}' under the key '${key} and not '${value}'"
 		return 1
 	fi
 }