[14/21] test: Add functions test_that_array_is_defined
 
Commit Message
  
  
we need this check in multiple places so it makes sense to move this to
a separate function.
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
 tests/lib.sh | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
  
 
  
@@ -27,17 +27,25 @@  var_has_value() {
 	[[ "${!1}" == "${2}" ]]
 }
 
-test_that_key_in_arry_has_value() {
-	local -n array="${1}"
+test_that_array_is_defined() {
 	local arrayname="${1}"
-	local key="${2}"
-	local value="${3}"
 
 	if [[ ! "$(declare  -p "${arrayname}")" =~ "declare -a" && ! "$(declare  -p "${arrayname}")" =~ "declare -A" ]]; then
 		log_test_failed "The array '${1}' does not exists. The variable is not set."
 		return 1
+	else
+		log_test_succeded "The array '${1}' is defined."
+		return 0
 	fi
+}
+
+test_that_key_in_arry_has_value() {
+	local -n array="${1}"
+	local arrayname="${1}"
+	local key="${2}"
+	local value="${3}"
 
+	test_that_array_is_defined "${arrayname}"  || return 1
 
 	if [[ "${array["${key}"]+_}" == ""  ]]; then
 		log_test_failed "The array does not contain the key '${key}', valid keys are: ${!array[*]}"