]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
tests: Add functions test_that_array_doesnt_have_key
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Sun, 16 Jun 2024 16:02:36 +0000 (18:02 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 24 Aug 2024 12:19:56 +0000 (12:19 +0000)
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>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/lib.sh

index 32481b6a52bb94b6f12fa67f3dd341d6d49c9a41..bb06e11c29cc202fd5e5fd4ac58480e029ea6798 100644 (file)
@@ -74,6 +74,24 @@ test_value_in_array() {
        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}"