From patchwork Sun Jun 16 16:02:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonatan Schlag X-Patchwork-Id: 7869 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 4W2Hqh1vM9z3wy2 for ; Sun, 16 Jun 2024 16:03:28 +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 4W2Hqc6V83z5nh; 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 4W2HqZ2R6Rz33Fq; Sun, 16 Jun 2024 16:03:22 +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 4W2HqW3QDSz33Fh 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 4W2HqV2wKTz5nY; Sun, 16 Jun 2024 16:03:18 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1718553798; 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=K+R69oApYUegk2dlnzkfAjG7DEKYJubT8Ru2E0NP7nk=; b=kC3TXWwpPhdH5fGF0Na6akaaxSvebMX4SjTDUkMEDFW6cc6KMH/ghKfVTpTl7ZtS74afg1 jYP8P2RBlSwzFpBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1718553798; 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=K+R69oApYUegk2dlnzkfAjG7DEKYJubT8Ru2E0NP7nk=; b=BQqdYc1wuRKd5/XacMO/lGUx53Uq4kyjxHVMvehgTBqfqa2XxFh8s/lT6vxkm+Pr7l/FsJ Q4RVh8R7l+vOGCsCuQldUJsa5PXVsEqdI1S65T8QFbv5P1oY7UAnivcTyos7Lwdx1kd6TU sxE3cAR8YtoZIsRTzijRamLYVAzBIu19Bc/OA6GB2seXqGfWGIH3IFilbrwflTmr8WsElW 2lej6KKbemlSdgwQVPERuZ/OoqPbloK67chKpuXw0lNwU6FL85n7MKYb4WOjULj2aowRxX AvRHzeyOvRdm2AuL7QT7yqmLO0hosd1PpVp7Ag/ccrtH6c1S7sRxQTPRIwxb/w== From: Jonatan Schlag To: development@lists.ipfire.org Subject: [PATCH v2 08/18] test: Add functions test_that_array_is_defined Date: Sun, 16 Jun 2024 18:02:35 +0200 Message-Id: <20240616160245.18865-9-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: LJQPDQ3PFWERCEAMZRX3NU47WWNGOUYW X-Message-ID-Hash: LJQPDQ3PFWERCEAMZRX3NU47WWNGOUYW 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 | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/lib.sh b/tests/lib.sh index 4110ed2d8..32481b6a5 100644 --- a/tests/lib.sh +++ b/tests/lib.sh @@ -34,11 +34,8 @@ var_has_value() { [[ "${!1}" == "${2}" ]] } -test_value_in_array() { - local -n array="${1}" +test_that_array_is_defined() { local arrayname="${1}" - local key="${2}" - local value="${3}" # `declare -p` print out how the variable with the name $arrayname was declared # If the array was not declared as indexed or associative array we fail. We cannot check for a value in an array if @@ -46,7 +43,19 @@ test_value_in_array() { 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_value_in_array() { + local -n array="${1}" + local arrayname="${1}" + local key="${2}" + local value="${3}" + + test_that_array_is_defined "${arrayname}" || return 1 # If key is not defined we return _ # If the key is defined we return nothing