From patchwork Sun Jun 16 16:02:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7868 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4W2Hqg61fQz3ws3 for ; Sun, 16 Jun 2024 16:03:27 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4W2Hqc6KY7z3tL; Sun, 16 Jun 2024 16:03:24 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4W2HqY1GqYz33G2; Sun, 16 Jun 2024 16:03:21 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4W2HqW0by2z2xtd for ; Sun, 16 Jun 2024 16:03:19 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4W2HqP1txqz5g4; Sun, 16 Jun 2024 16:03:13 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553793; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ws7xV8FM5OZxfsTlvvZ2u7V5awT6lq9LDxLjlMoc/Uc=; b=b7uafPOzeLu0II0kOQq2YjfdlZWg/QYX4fba6kU9Elt4WwrThCaYpqz0R+BeUVYtdOq4hQ G5G7hUowu48azOBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553793; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ws7xV8FM5OZxfsTlvvZ2u7V5awT6lq9LDxLjlMoc/Uc=; b=aP3Yqg9sQDNKciRsFrLON2eyCufTJ5tDA+vSDc37saJkF3JcGA3BDROKtGcMfjSy4CgL6I +ataJ6J1rQRw6MyzSUc6dHo79xJ4KOuow9JtQ/GjWhiK9GrzyqVhVHthD4WtM8Wxn7nlZo oQYOryKRdyAhBCCNdNk4EUPgl2pqBSyBEwxdCCCjj1zf83Xzgx8QRkjv+Wd/4kbC1HiIgv pRe2M2Ozy5VHQXajAIaNzBE/QSl1EMjzDYqB05BdQDj+Pj2x6kKF4K7z0nuwtCKDJ0+JJB mNnLSNObarhbSPhrgzMKWLW1GPG0uDRk6096j/goDAuNhbog7+am89z8/rlpXg== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 06/18] test_value_in_array: Check if the key is defined Date: Sun, 16 Jun 2024 18:02:33 +0200 Message-Id: <20240616160245.18865-7-jonatan.schlag@ipfire.org> In-Reply-To: <20240616160245.18865-1-jonatan.schlag@ipfire.org> References: <20240616160245.18865-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: CYPOVSEIFOHFY7EYL2T6ECBS2E53VIO5 X-Message-ID-Hash: CYPOVSEIFOHFY7EYL2T6ECBS2E53VIO5 X-MailFrom: jonatan.schlag@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-off-by: Jonatan Schlag --- tests/lib.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/lib.sh b/tests/lib.sh index f49a94748..af8c632cf 100644 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -48,6 +48,14 @@ test_value_in_array() { return 1 fi + # If key is not defined we return _ + # If the key is defined we return nothing + # See also https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html + if [[ "${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