[08/21] test_that_key_in_arry_has_value: Check if the key is defined

Message ID 20240520090611.10406-9-jonatan.schlag@ipfire.org
State New
Headers
Series [01/21] test: Add bash lib for colors |

Commit Message

Jonatan Schlag May 20, 2024, 9:05 a.m. UTC
  Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
 tests/lib.sh | 5 +++++
 1 file changed, 5 insertions(+)
  

Patch

diff --git a/tests/lib.sh b/tests/lib.sh
index 0f4de8e43..006862da6 100644
--- a/tests/lib.sh
+++ b/tests/lib.sh
@@ -38,6 +38,11 @@  test_that_key_in_arry_has_value() {
 		return 1
 	fi
 
+	if [[ ! -v "${array[${key}]}" ]]; then
+		log_test_failed "The array does not contain the key '${key}', valid keys are: ${!array[*]}"
+		return 1
+	fi
+
 	if [[ "${array[${key}]}" == "${value}" ]] ; then
 		log_test_succeded "The array '${1}' contains the value '${value}' under the key '${key}'"
 		return 0