[10/21] test_that_key_in_arry_has_value: Check if a key in an array exists

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

Commit Message

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

Patch

diff --git a/tests/lib.sh b/tests/lib.sh
index ad7c12cb0..81bc1439c 100644
--- a/tests/lib.sh
+++ b/tests/lib.sh
@@ -38,7 +38,8 @@  test_that_key_in_arry_has_value() {
 		return 1
 	fi
 
-	if [[ ! -v "${array[${key}]}" ]]; then
+
+	if [[ "${array["${key}"]+_}" == ""  ]]; then
 		log_test_failed "The array does not contain the key '${key}', valid keys are: ${!array[*]}"
 		return 1
 	fi