From c26f647a3a2cda293ef6c3789d5630f6aa8bafe1 Mon Sep 17 00:00:00 2001 From: Alex Lyn Date: Mon, 13 Apr 2026 11:23:42 +0800 Subject: [PATCH] test: Improve process verification and robustness in kill test During tests, one error as below: ``` ..k8s-kill-all-process-in-container.bats: line 40: [: too many arguments ``` This commit aims to address such issue follows: (1) Update process query command to "ps aux || ps" to ensure compatibility across different container images while maximizing process visibility. (2) Use "[t]ail" in grep to reliably match the process without self-matching. (3) Quote variable in assertion to resolve "too many arguments" bash error. (4) Improve test reliability by ensuring the process list is actually visible to the verification logic. Signed-off-by: Alex Lyn --- .../k8s-kill-all-process-in-container.bats | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/integration/kubernetes/k8s-kill-all-process-in-container.bats b/tests/integration/kubernetes/k8s-kill-all-process-in-container.bats index 90ef5b262e..fa2fe66c31 100644 --- a/tests/integration/kubernetes/k8s-kill-all-process-in-container.bats +++ b/tests/integration/kubernetes/k8s-kill-all-process-in-container.bats @@ -19,8 +19,9 @@ setup() { policy_settings_dir="$(create_tmp_policy_settings_dir "${pod_config_dir}")" - command="ps" - add_exec_to_policy_settings "${policy_settings_dir}" "${command}" + command="ps aux || ps" + + add_exec_to_policy_settings "${policy_settings_dir}" "sh" "-c" "${command}" add_requests_to_policy_settings "${policy_settings_dir}" "ReadStreamRequest" auto_generate_policy "${policy_settings_dir}" "${yaml_file}" @@ -34,10 +35,14 @@ setup() { kubectl wait --for=condition=Ready --timeout=$timeout pod $pod_name # Check PID from first container - first_pid_container=$(kubectl exec $pod_name -c $first_container_name \ - -- $command | grep "tail" || true) + # Capture kubectl exec output separately so a failed exec is not hidden + # by the downstream grep. Use 'sh -c' to ensure the shell interprets + # $command correctly, and "[t]ail" to prevent grep itself from appearing. + exec_output=$(kubectl exec $pod_name -c $first_container_name \ + -- sh -c "$command") + first_pid_container=$(echo "$exec_output" | grep "[t]ail" || true) # Verify that the tail process didn't exist - [ -z $first_pid_container ] || die "found processes pid: $first_pid_container" + [ -z "$first_pid_container" ] || die "found processes pid: $first_pid_container" } teardown() {