From patchwork Mon May 20 09:06:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7799 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 4VjWsp1Qvjz3wxV for ; Mon, 20 May 2024 09:07:10 +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 4VjWsl3szNz5nT; Mon, 20 May 2024 09:07:07 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4VjWsJ1HZXz337G; Mon, 20 May 2024 09:06:44 +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 4VjWsD3tThz337G for ; Mon, 20 May 2024 09:06:40 +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 4VjWs84y0gz5gj; Mon, 20 May 2024 09:06:36 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1716195996; 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=5J65laUWy5/ZbKGuZsh5kQkkhXttJoe8CfjybmBJvng=; b=FhxhD9zloCPW0vKEWdx3FHAP1ItCQB2k4TjvnVFl12+8fwMoMsd0ArBpKo1pgKuzYGZhod nqifsrZtaD9R/OCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1716195996; 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=5J65laUWy5/ZbKGuZsh5kQkkhXttJoe8CfjybmBJvng=; b=Xq7OmCdKDkJnBfgvAuksJYNSzrNCLBsOz7fusn15G3WeRDBIMS0oKJG1W5Xf9kEVAM3Qlc aDkPy2iz1lXE7CGlQCidmXbAjVVKk4kmZMv29YtqxR20oSGqjUTCQ7uq20+4bJn/BQqSUl eKGmxNYtWYGS5774EVLb41dHaccJfXpYj3agSw/ntcCj9W6TUDEbHp3mvIXKcS1VKPHaIc o/AFGZsBN03V/TiIpdXGoN+PEN7FQRM7RkjdI+55mYovfJ8Z4rnu4ktfS9YaYXG1iFrgba nNsDFnDU/dbmDtyQQMXXN8s5+kv5ddV6UrfcDyG5HJ1hIZeXaCRGbKapX9Zh+A== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH 14/21] test: Add functions test_that_array_is_defined Date: Mon, 20 May 2024 11:06:04 +0200 Message-Id: <20240520090611.10406-15-jonatan.schlag@ipfire.org> In-Reply-To: <20240520090611.10406-1-jonatan.schlag@ipfire.org> References: <20240520090611.10406-1-jonatan.schlag@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: FPIGW65IVG2EAS5Q6NJKJV4MJV3VJIVK X-Message-ID-Hash: FPIGW65IVG2EAS5Q6NJKJV4MJV3VJIVK 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: we need this check in multiple places so it makes sense to move this to a separate function. Signed-off-by: Jonatan Schlag --- tests/lib.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/lib.sh b/tests/lib.sh index 9ce0201b1..29f4e3b71 100644 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -27,17 +27,25 @@ var_has_value() { [[ "${!1}" == "${2}" ]] } -test_that_key_in_arry_has_value() { - local -n array="${1}" +test_that_array_is_defined() { local arrayname="${1}" - local key="${2}" - local value="${3}" if [[ ! "$(declare -p "${arrayname}")" =~ "declare -a" && ! "$(declare -p "${arrayname}")" =~ "declare -A" ]]; then log_test_failed "The array '${1}' does not exists. The variable is not set." return 1 + else + log_test_succeded "The array '${1}' is defined." + return 0 fi +} + +test_that_key_in_arry_has_value() { + local -n array="${1}" + local arrayname="${1}" + local key="${2}" + local value="${3}" + test_that_array_is_defined "${arrayname}" || return 1 if [[ "${array["${key}"]+_}" == "" ]]; then log_test_failed "The array does not contain the key '${key}', valid keys are: ${!array[*]}"