From 2cf2846c6b2c9b39cbb059484d207d5c0a92d6c8 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 8 May 2026 18:51:02 -0400 Subject: [PATCH 1/5] test: count assert_output_contains matches as fixed strings Replace the bash pattern-substitution loop with grep -F -o piped to wc -l so the helper counts literal substring occurrences instead of treating the expected value as a glob pattern. The old implementation interpreted `[`, `]`, `*`, `?`, and `\` as pattern syntax, which made `assert_output_contains "['task.py', 'test']"` report 17 matches against an output that contained the string exactly once - the inner characters were being matched as a character class. assert_output_not_contains delegates to assert_output_contains and is fixed transitively. --- tests/unit/test_helper.bash | 7 ++----- tests/unit/traefik.bats | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index 60ba322e9..08fbd4a63 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -143,11 +143,8 @@ assert_output_contains() { local input="$output" local expected="$1" local count="${2:-1}" - local found=0 - until [ "${input/$expected/}" = "$input" ]; do - input="${input/$expected/}" - found=$((found + 1)) - done + local found + found=$(printf '%s' "$input" | grep -F -o -- "$expected" | wc -l | tr -d ' ') if [[ "$count" -eq -1 ]]; then if [[ "$found" -gt 0 ]]; then diff --git a/tests/unit/traefik.bats b/tests/unit/traefik.bats index f07f2a6f6..9c808d89e 100644 --- a/tests/unit/traefik.bats +++ b/tests/unit/traefik.bats @@ -468,7 +468,7 @@ teardown() { assert_success assert_output_contains "dns provider cf_api_email" assert_output_contains "dns provider cf_api_key" - assert_output_contains "*******" + assert_output_contains "*******" 2 assert_output_not_contains "test@example.com" assert_output_not_contains "secret-key" From 01268ebad91df95ada82dbbfa30fa61758837caa Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 8 May 2026 21:38:22 -0400 Subject: [PATCH 2/5] tests: fix count --- tests/unit/traefik.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/traefik.bats b/tests/unit/traefik.bats index 9c808d89e..0cfc6dc13 100644 --- a/tests/unit/traefik.bats +++ b/tests/unit/traefik.bats @@ -548,7 +548,7 @@ teardown() { echo "output: $output" echo "status: $status" assert_success - assert_output_contains "*******" + assert_output_contains "*******" 2 assert_output_not_contains "test@example.com" assert_output_not_contains "secret-key" From 38de83eabf3b837d3e116b2c677052b3e4631d2b Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 8 May 2026 21:39:57 -0400 Subject: [PATCH 3/5] tests: use inverted assert Also echo the status --- tests/unit/init.bats | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/unit/init.bats b/tests/unit/init.bats index 1cd143a32..616d098f4 100644 --- a/tests/unit/init.bats +++ b/tests/unit/init.bats @@ -24,7 +24,8 @@ teardown() { run "$DOCKER_BIN" container top "$CIDS" echo "output: $output" - assert_output_contains "" "0" + echo "status: $status" + assert_output_not_contains "" } @test "(init) dockerfile no tini" { @@ -39,7 +40,8 @@ teardown() { run "$DOCKER_BIN" container top "$CIDS" echo "output: $output" - assert_output_contains "" "0" + echo "status: $status" + assert_output_not_contains "" } @test "(init) dockerfile with tini" { @@ -54,5 +56,6 @@ teardown() { run "$DOCKER_BIN" container top "$CIDS" echo "output: $output" - assert_output_contains "" "0" + echo "status: $status" + assert_output_not_contains "" } From 25abd38387a76595fb86e673f0c7bf0a49aec7c8 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 9 May 2026 10:48:29 -0400 Subject: [PATCH 4/5] tests: use /bin/bash -c to execute commands in init tests --- tests/unit/init.bats | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/init.bats b/tests/unit/init.bats index 616d098f4..c432a934c 100644 --- a/tests/unit/init.bats +++ b/tests/unit/init.bats @@ -22,7 +22,7 @@ teardown() { local CIDS=$(get_app_container_ids "$APP") - run "$DOCKER_BIN" container top "$CIDS" + run /bin/bash -c "$DOCKER_BIN container top $CIDS" echo "output: $output" echo "status: $status" assert_output_not_contains "" @@ -38,7 +38,7 @@ teardown() { local CIDS=$(get_app_container_ids "$APP") - run "$DOCKER_BIN" container top "$CIDS" + run /bin/bash -c "$DOCKER_BIN container top $CIDS" echo "output: $output" echo "status: $status" assert_output_not_contains "" @@ -54,7 +54,7 @@ teardown() { local CIDS=$(get_app_container_ids "$APP") - run "$DOCKER_BIN" container top "$CIDS" + run /bin/bash -c "$DOCKER_BIN container top $CIDS" echo "output: $output" echo "status: $status" assert_output_not_contains "" From f4213a4bf505990a0e4deafd46da21f54081b4f7 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 9 May 2026 13:36:29 -0400 Subject: [PATCH 5/5] tests: prevent assert_output_contains from aborting on no match Bats runs tests under `set -eo pipefail`, so when `grep -F -o` finds nothing inside the count pipe it exits 1, the whole pipe fails, errexit fires, and the function aborts before reaching the count comparison. Wrap grep in `{ ... || true; }` so the pipe stays zero when the pattern is absent and the helper falls through to the flunk message. --- tests/unit/test_helper.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index 08fbd4a63..a998d67bc 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -144,7 +144,7 @@ assert_output_contains() { local expected="$1" local count="${2:-1}" local found - found=$(printf '%s' "$input" | grep -F -o -- "$expected" | wc -l | tr -d ' ') + found=$(printf '%s' "$input" | { grep -F -o -- "$expected" || true; } | wc -l | tr -d ' ') if [[ "$count" -eq -1 ]]; then if [[ "$found" -gt 0 ]]; then