Skip to content

Commit 28044aa

Browse files
committed
test(backups): drive the new demo bats through cozytest.sh's dialect
The kafka-metadata and nats helper tests were written for stock bats (run/$status/setup), which hack/cozytest.sh's awk runner does not execute -- under CI `run` is command-not-found and the assertions never fire. Rewrite them in the runner's dialect the redis test already uses: no run/$status/setup, each case builds its own stubs, direct shell tests that exit non-zero, and helper functions closing on an indented brace so the column-0 `}` rewrite cannot mask their exit status. Assisted-by: LLM Signed-off-by: IvanHunters <[email protected]>
1 parent b2e7765 commit 28044aa

2 files changed

Lines changed: 27 additions & 23 deletions

File tree

‎hack/kafka-metadata-backup-demo-helpers.bats‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
# answers only the calls kafka_run is expected to make -- get/wait for the
77
# long-lived CLI Pod and an `exec` into it -- and runs the exec'd snippet locally
88
# against the kafka-topics.sh stub. A throwaway `kubectl run -i` Pod (the old
9-
# attach-racing path) makes the stub exit non-zero, so any test that gets a
10-
# correct reply proves the reply came back through exec, not that path.
9+
# attach-racing path) makes the stub exit non-zero, so a test that gets the right
10+
# reply proves it came back through exec, not that path.
1111
#
12-
# The helpers are Bash and this runner is POSIX sh, so each case drives them
13-
# through `bash -c` under the same `set -euo pipefail` the demo scripts use. The
12+
# cozytest.sh's awk runner recognizes only @test blocks and a bare `}`; there is
13+
# no bats `run` or `$status`, and no setup/teardown, so each case calls
14+
# make_stubs itself and asserts with direct shell tests that exit non-zero. The
1415
# helper functions close on an indented brace because the runner rewrites a
1516
# column-0 `}` into `return 0`, which would mask run_topic_meta's exit status.
1617

17-
setup() {
18+
make_stubs() {
1819
stub=$(mktemp -d)
1920
cat > "$stub/kubectl" <<'EOF'
2021
#!/bin/bash
@@ -60,16 +61,17 @@ run_topic_meta() {
6061
}
6162

6263
@test "kafka_run reads the reply by exec into the long-lived CLI Pod" {
63-
run run_topic_meta
64-
[ "$status" -eq 0 ]
65-
[ "$output" = "3 123456" ]
64+
make_stubs
65+
out=$(run_topic_meta)
66+
[ "$out" = "3 123456" ]
6667
grep -q 'exec -i kafka-cli -- bash -c' "$stub/kubectl.argv"
6768
}
6869

6970
@test "kafka_run starts the CLI Pod when it is absent, then execs into it" {
70-
STUB_NO_POD=1 run run_topic_meta
71-
[ "$status" -eq 0 ]
72-
[ "$output" = "3 123456" ]
71+
make_stubs
72+
export STUB_NO_POD=1
73+
out=$(run_topic_meta)
74+
[ "$out" = "3 123456" ]
7375
grep -q 'run kafka-cli --image=' "$stub/kubectl.argv"
7476
grep -q 'exec -i kafka-cli -- bash -c' "$stub/kubectl.argv"
7577
}

‎hack/nats-backup-demo-helpers.bats‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
# kubectl and the `nats` CLI are stub executables on PATH. The kubectl stub
66
# answers only the calls nats_cli is expected to make -- get/wait for the
77
# long-lived CLI Pod and an `exec` into it -- and runs the exec'd `nats`
8-
# invocation locally against the nats stub. A throwaway `kubectl run -i` Pod
9-
# (the old attach-racing path) makes the stub exit non-zero, so any test that
10-
# gets a correct reply proves the reply came back through exec, not that path.
8+
# invocation locally against the nats stub. A throwaway `kubectl run -i` Pod (the
9+
# old attach-racing path) makes the stub exit non-zero, so a test that gets the
10+
# right reply proves it came back through exec, not that path.
1111
#
12-
# The helpers are Bash and this runner is POSIX sh, so each case drives them
13-
# through `bash -c` under the same `set -euo pipefail` the demo scripts use. The
12+
# cozytest.sh's awk runner recognizes only @test blocks and a bare `}`; there is
13+
# no bats `run` or `$status`, and no setup/teardown, so each case calls
14+
# make_stubs itself and asserts with direct shell tests that exit non-zero. The
1415
# helper functions close on an indented brace because the runner rewrites a
1516
# column-0 `}` into `return 0`, which would mask run_stream_count's exit status.
1617

17-
setup() {
18+
make_stubs() {
1819
stub=$(mktemp -d)
1920
cat > "$stub/kubectl" <<'EOF'
2021
#!/bin/bash
@@ -60,16 +61,17 @@ run_stream_count() {
6061
}
6162

6263
@test "nats_cli reads the reply by exec into the long-lived CLI Pod" {
63-
run run_stream_count
64-
[ "$status" -eq 0 ]
65-
[ "$output" = "42" ]
64+
make_stubs
65+
out=$(run_stream_count)
66+
[ "$out" = "42" ]
6667
grep -q 'exec -i nats-cli -- nats' "$stub/kubectl.argv"
6768
}
6869

6970
@test "nats_cli starts the CLI Pod when it is absent, then execs into it" {
70-
STUB_NO_POD=1 run run_stream_count
71-
[ "$status" -eq 0 ]
72-
[ "$output" = "42" ]
71+
make_stubs
72+
export STUB_NO_POD=1
73+
out=$(run_stream_count)
74+
[ "$out" = "42" ]
7375
grep -q 'run nats-cli --image=' "$stub/kubectl.argv"
7476
grep -q 'exec -i nats-cli -- nats' "$stub/kubectl.argv"
7577
}

0 commit comments

Comments
 (0)