From 835c6814d76ac9a1a00d36661efcb43826df2eea Mon Sep 17 00:00:00 2001 From: Dan Mihai Date: Wed, 19 Mar 2025 00:20:20 +0000 Subject: [PATCH] tests: k8s/tests_common: avoid using regex More straightforward implementation of hard_coded_policy_tests_enabled, that avoids ShellCheck warning: warning: Remove quotes from right-hand side of =~ to match as a regex rather than literally. [SC2076] Signed-off-by: Dan Mihai --- tests/integration/kubernetes/tests_common.sh | 23 ++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/integration/kubernetes/tests_common.sh b/tests/integration/kubernetes/tests_common.sh index 1f2ede004e..d87c9fad43 100644 --- a/tests/integration/kubernetes/tests_common.sh +++ b/tests/integration/kubernetes/tests_common.sh @@ -274,13 +274,28 @@ add_copy_from_guest_to_policy_settings() { } hard_coded_policy_tests_enabled() { + local enabled="no" # CI is testing hard-coded policies just on a the platforms listed here. Outside of CI, # users can enable testing of the same policies (plus the auto-generated policies) by # specifying AUTO_GENERATE_POLICY=yes. - local enabled_hypervisors="qemu-coco-dev qemu-sev qemu-snp qemu-tdx" - [[ " ${enabled_hypervisors} " =~ " ${KATA_HYPERVISOR} " ]] || \ - [[ "${KATA_HOST_OS}" == "cbl-mariner" ]] || \ - auto_generate_policy_enabled + local -r enabled_hypervisors=("qemu-coco-dev" "qemu-sev" "qemu-snp" "qemu-tdx") + for enabled_hypervisor in "${enabled_hypervisors[@]}" + do + if [[ "${enabled_hypervisor}" == "${KATA_HYPERVISOR}" ]]; then + enabled="yes" + break + fi + done + + if [[ "${enabled}" == "no" && "${KATA_HOST_OS}" == "cbl-mariner" ]]; then + enabled="yes" + fi + + if [[ "${enabled}" == "no" ]] && auto_generate_policy_enabled; then + enabled="yes" + fi + + [[ "${enabled}" == "yes" ]] } add_allow_all_policy_to_yaml() {