Skip to content

Commit 0123b20

Browse files
committed
test: make negative bats assertions fail under cozytest
These bats files are all run by hack/cozytest.sh, which executes each @test under `set -e`. POSIX errexit is suppressed for a pipeline that begins with `!`, so a bare `! cmd` must-not-happen assertion never fails the test: when the forbidden condition actually occurs (cmd succeeds) the negated pipeline returns non-zero but errexit ignores it and the test passes anyway. These assertions were silently vacuous. Replace each with `if cmd; then echo "<reason>"; false; fi`, the idiom already used and documented elsewhere in these files — the if-condition is exempt from errexit and the `false` in the taken branch fails the test loudly. The forbidden condition now fails the test as intended: - bucket: read-only user must not be able to upload (access control) - gateway: child tenant must not have its own gateway HelmRelease - kuberture: external-dns public/internal hostname isolation - e2e-install: tenant-name validation must reject (not warn); the version ConfigMap must be gone after delete - build-matrix: talos/installer excluded from the parallel matrix - capture-dataplane: kube-dns and pending rows are filtered out Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent eab9b03 commit 0123b20

6 files changed

Lines changed: 33 additions & 13 deletions

File tree

‎hack/build-matrix_test.bats‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ setup() {
1818

1919
@test "talos and installer are excluded from the parallel matrix" {
2020
out=$(hack/build-matrix.sh)
21-
! echo "$out" | grep -q '"packages/core/talos"'
22-
! echo "$out" | grep -q '"packages/core/installer"'
21+
# `! cmd` would be vacuous: cozytest.sh runs each @test under `set -e`, which
22+
# is suppressed for a `!`-negated pipeline, so a regression that wrongly
23+
# included these paths would not fail the test. Assert via `if cmd; then ...`.
24+
if echo "$out" | grep -q '"packages/core/talos"'; then echo "FAIL: packages/core/talos must be excluded from the parallel matrix"; false; fi
25+
if echo "$out" | grep -q '"packages/core/installer"'; then echo "FAIL: packages/core/installer must be excluded from the parallel matrix"; false; fi
2326
}
2427

2528
@test "talos-only diff selects nothing (handled by the dedicated leg)" {

‎hack/capture-dataplane.bats‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ E2E_CAPTURE_DATAPLANE_LIB=1
5353
[ "$(printf '%s\n' "$out" | grep -c .)" -eq 2 ]
5454
printf '%s\n' "$out" | grep -q '^tenant|app|LoadBalancer|192.0.2.50|'
5555
printf '%s\n' "$out" | grep -q '^tenant|db|LoadBalancer|192.0.2.51|'
56-
! printf '%s\n' "$out" | grep -q 'kube-dns'
57-
! printf '%s\n' "$out" | grep -q 'pending'
56+
# `! cmd` is vacuous under cozytest's `set -e` (errexit is suppressed for a
57+
# `!`-negated pipeline), so a filter regression that let these rows through
58+
# would not fail the test. Assert the absence via `if cmd; then ...; false`.
59+
if printf '%s\n' "$out" | grep -q 'kube-dns'; then echo "FAIL: lb_filter_services must drop the kube-dns row"; false; fi
60+
if printf '%s\n' "$out" | grep -q 'pending'; then echo "FAIL: lb_filter_services must drop the pending (no external IP) row"; false; fi
5861
}
5962

6063
@test "lb_first_ready_endpoint picks the first addressed endpoint that is not NotReady" {

‎hack/e2e-apps/bucket.bats‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,12 @@ EOF
8585
# Viewer can download
8686
mc cp --insecure ro-user/$BUCKET_NAME/rw-test.txt /tmp/ro-test-download.txt
8787

88-
# Viewer cannot upload (must fail with Access Denied)
88+
# Viewer cannot upload (must fail with Access Denied). A bare `! mc cp` is
89+
# vacuous under cozytest's `set -e` (errexit is suppressed for a `!` pipeline),
90+
# so a real access-control regression that let the upload through would pass
91+
# silently — assert via `if mc cp; then ...; false` so it fails loudly.
8992
echo "readonly test" > /tmp/ro-test.txt
90-
! mc cp --insecure /tmp/ro-test.txt ro-user/$BUCKET_NAME/ro-test.txt
93+
if mc cp --insecure /tmp/ro-test.txt ro-user/$BUCKET_NAME/ro-test.txt; then echo "FAIL: read-only user must NOT be able to upload (bucket access-control regression)"; false; fi
9194

9295
# --- Cleanup ---
9396
mc rm --insecure rw-user/$BUCKET_NAME/rw-test.txt

‎hack/e2e-apps/gateway.bats‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,11 @@ EOF
540540
echo "$cozyvalues" | grep -E '^\s*gateway:\s*"tenant-test-gwparent"\s*$' >/dev/null
541541

542542
# The child must NOT have its own gateway HelmRelease — inheritance
543-
# means no separate Gateway resource for the child tenant.
544-
! kubectl -n tenant-test-gwparent-gwchild get helmrelease gateway 2>/dev/null
543+
# means no separate Gateway resource for the child tenant. A bare `! kubectl`
544+
# is vacuous under cozytest's `set -e` (suppressed for a `!` pipeline), so if
545+
# the child wrongly got its own HelmRelease the test would still pass; assert
546+
# via `if kubectl get; then ...; false`.
547+
if kubectl -n tenant-test-gwparent-gwchild get helmrelease gateway 2>/dev/null; then echo "FAIL: child tenant must NOT have its own gateway HelmRelease (gateway inheritance broken)"; false; fi
545548

546549
# Teardown child before parent, waiting out each uninstall: deleting
547550
# the parent while the child is still uninstalling wedges the parent's

‎hack/e2e-apps/kuberture.bats‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,15 @@ EOF
236236
# kuberture-e2e-public.cozystack.test (kuberture-e2e-public Service carries
237237
# external-dns.alpha.kubernetes.io/hostname=...) and must NOT see the
238238
# internal hostname (kuberture-e2e-internal carries only the internal prefix).
239+
# A bare `! echo | grep` is vacuous under cozytest's `set -e` (errexit is
240+
# suppressed for a `!` pipeline), so a leak of the wrong hostname into a probe
241+
# would not fail the test; assert the absence via `if ... grep; then ...; false`.
239242
echo "${pub_logs}" | grep -F "${pub_host}" >/dev/null
240-
! echo "${pub_logs}" | grep -F "${int_host}" >/dev/null
243+
if echo "${pub_logs}" | grep -F "${int_host}" >/dev/null; then echo "FAIL: public-prefix probe must NOT see the internal hostname ${int_host}"; false; fi
241244

242245
# And the inverse for the internal-prefix probe.
243246
echo "${int_logs}" | grep -F "${int_host}" >/dev/null
244-
! echo "${int_logs}" | grep -F "${pub_host}" >/dev/null
247+
if echo "${int_logs}" | grep -F "${pub_host}" >/dev/null; then echo "FAIL: internal-prefix probe must NOT see the public hostname ${pub_host}"; false; fi
245248

246249
# _cleanup deletes the probe Pods, their SA, the ClusterRole+ClusterRoleBinding,
247250
# and finally the Package CR. Inlined here for the success path so a re-run

‎hack/e2e-install-cozystack.bats‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,10 @@ EOF
289289
# generic DNS-1035 errors and from network/auth failures).
290290
echo "$output" | grep -q "tenant names must"
291291
# And assert kubectl did NOT report creation — if validation regressed
292-
# into a "warn" variant, the server could still accept the object.
293-
! echo "$output" | grep -qi "created"
292+
# into a "warn" variant, the server could still accept the object. A bare
293+
# `! echo | grep` is vacuous under cozytest's `set -e` (suppressed for a `!`
294+
# pipeline), so the regression would slip through; assert via `if ...; false`.
295+
if echo "$output" | grep -qi "created"; then echo "FAIL: kubectl reported the tenant as created — validation must reject it, not warn"; false; fi
294296

295297
# Post-condition cleanup: even though we expect validation to reject the
296298
# create, removing foo-bar unconditionally keeps the cluster clean for
@@ -395,7 +397,10 @@ EOF
395397
version=$(kubectl get configmap cozystack-version -n cozy-system \
396398
-o jsonpath='{.data.version}')
397399
kubectl delete configmap cozystack-version -n cozy-system
398-
! kubectl get configmap cozystack-version -n cozy-system 2>/dev/null
400+
# A bare `! kubectl get` is vacuous under cozytest's `set -e` (errexit is
401+
# suppressed for a `!` pipeline), so a delete that silently failed would not
402+
# fail the test; assert the absence via `if kubectl get; then ...; false`.
403+
if kubectl get configmap cozystack-version -n cozy-system 2>/dev/null; then echo "FAIL: cozystack-version configmap must be gone after delete with the no-delete label removed"; false; fi
399404
# Reconstruct: declarative apply matches the chart template at
400405
# packages/core/platform/templates/cozystack-version.yaml — same label set
401406
# AND the helm.sh/resource-policy: keep annotation that pins the ConfigMap

0 commit comments

Comments
 (0)