[15/21] tests: Add functions test_that_array_doesnt_have_key

Message ID 20240520090611.10406-16-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
  Apparently we can set way more keys then I expected. So we need a
function to check that we do not set certain key. Some keys need to be
skipped.

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

Patch

diff --git a/tests/lib.sh b/tests/lib.sh
index 29f4e3b71..1eab92cf7 100644
--- a/tests/lib.sh
+++ b/tests/lib.sh
@@ -61,6 +61,24 @@  test_that_key_in_arry_has_value() {
 	fi
 }
 
+test_that_array_doesnt_have_key() {
+	local -n array="${1}"
+	local arrayname="${1}"
+	local key="${2}"
+
+	test_that_array_is_defined "${arrayname}"  || return 1
+
+	if [[ "${array["${key}"]+_}" == "_"  ]]; then
+		log_test_failed "The array '${arrayname}' does contain the key '${key}'."
+		return 1
+	else
+		log_test_succeded "The array '${arrayname}' does not contain the key '${key}'"
+		return 0
+	fi
+
+}
+
+
 test_that_output_is(){
 	local reference_output_file="${1}"
 	local file_descriptor="${2}"