Skip to content

Commit 77f80b5

Browse files
fix(ci): make select-e2e_test.bats run under cozytest.sh
CI invokes hack/cozytest.sh, a project-local pure-shell harness, not bats. cozytest does not honor setup()/teardown() and does not provide bats' run / $status / $output, so the original tests failed with "TMPDIR: parameter not set" under set -u. Inline tmpdir creation and an EXIT trap for cleanup in each test. Replace `run` + `$output` with direct command substitution, and replace `! grep` (which set -e ignores) with an explicit if-then-exit. Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent 6e5379e commit 77f80b5

1 file changed

Lines changed: 87 additions & 56 deletions

File tree

‎hack/select-e2e_test.bats‎

Lines changed: 87 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,121 @@
11
#!/usr/bin/env bats
2-
3-
setup() {
4-
TMPDIR=$(mktemp -d)
5-
cp -r packages/core/platform/sources $TMPDIR/sources
6-
}
2+
# -----------------------------------------------------------------------------
3+
# Unit tests for hack/select-e2e.sh
4+
#
5+
# cozytest.sh's awk parser recognizes only @test blocks and a bare `}` on its
6+
# own line; there is no bats `run` or `$status`. Each test runs as a shell
7+
# function under `set -eu -x`, so assertions are direct shell tests that exit
8+
# non-zero on failure. setup()/teardown() are not honored — each test creates
9+
# and cleans its own scratch dir.
10+
#
11+
# Run with: hack/cozytest.sh hack/select-e2e_test.bats
12+
# -----------------------------------------------------------------------------
713

814
@test "single app diff selects only that bats" {
9-
echo "packages/apps/postgres/values.yaml" > $TMPDIR/diff
10-
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
11-
[ "$status" -eq 0 ]
12-
[ "$output" = "postgres" ]
15+
tmp=$(mktemp -d)
16+
trap 'rm -rf "$tmp"' EXIT
17+
cp -r packages/core/platform/sources "$tmp/sources"
18+
echo "packages/apps/postgres/values.yaml" > "$tmp/diff"
19+
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
20+
[ "$output" = "postgres" ]
1321
}
1422

1523
@test "operator diff selects all dependent app bats" {
16-
# postgres-operator is depended on by postgres-application, harbor-application
17-
# (Harbor uses postgres as its backing DB), and monitoring-application (Grafana
18-
# DB). monitoring isn't in hack/e2e-apps/ so it's filtered out by the selector.
19-
echo "packages/system/postgres-operator/values.yaml" > $TMPDIR/diff
20-
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
21-
[ "$status" -eq 0 ]
22-
echo "$output" | grep -wq postgres
23-
echo "$output" | grep -wq harbor
24-
# Must NOT trigger full suite — confirm an unrelated bats is absent
25-
! echo "$output" | grep -wq kafka
24+
# postgres-operator is depended on by postgres-application, harbor-application
25+
# (Harbor uses postgres as its backing DB), and monitoring-application (Grafana
26+
# DB). monitoring isn't in hack/e2e-apps/ so it's filtered out by the selector.
27+
tmp=$(mktemp -d)
28+
trap 'rm -rf "$tmp"' EXIT
29+
cp -r packages/core/platform/sources "$tmp/sources"
30+
echo "packages/system/postgres-operator/values.yaml" > "$tmp/diff"
31+
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
32+
echo "$output" | grep -wq postgres
33+
echo "$output" | grep -wq harbor
34+
if echo "$output" | grep -wq kafka; then
35+
echo "operator diff must not trigger full suite; got: $output" >&2
36+
exit 1
37+
fi
2638
}
2739

2840
@test "networking change triggers full suite" {
29-
echo "packages/system/cilium/values.yaml" > $TMPDIR/diff
30-
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
31-
[ "$status" -eq 0 ]
32-
# Full suite means more than 5 bats files
33-
[ "$(echo $output | wc -w)" -gt 5 ]
41+
tmp=$(mktemp -d)
42+
trap 'rm -rf "$tmp"' EXIT
43+
cp -r packages/core/platform/sources "$tmp/sources"
44+
echo "packages/system/cilium/values.yaml" > "$tmp/diff"
45+
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
46+
# Full suite means more than 5 bats files
47+
[ "$(echo "$output" | wc -w)" -gt 5 ]
3448
}
3549

3650
@test "library change triggers full suite" {
37-
echo "packages/library/cozy-lib/templates/_helpers.tpl" > $TMPDIR/diff
38-
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
39-
[ "$(echo $output | wc -w)" -gt 5 ]
51+
tmp=$(mktemp -d)
52+
trap 'rm -rf "$tmp"' EXIT
53+
cp -r packages/core/platform/sources "$tmp/sources"
54+
echo "packages/library/cozy-lib/templates/_helpers.tpl" > "$tmp/diff"
55+
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
56+
[ "$(echo "$output" | wc -w)" -gt 5 ]
4057
}
4158

4259
@test "docs-only diff selects nothing" {
43-
echo "docs/README.md" > $TMPDIR/diff
44-
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
45-
[ "$status" -eq 0 ]
46-
[ -z "$output" ]
60+
tmp=$(mktemp -d)
61+
trap 'rm -rf "$tmp"' EXIT
62+
cp -r packages/core/platform/sources "$tmp/sources"
63+
echo "docs/README.md" > "$tmp/diff"
64+
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
65+
[ -z "$output" ]
4766
}
4867

4968
@test "kubernetes-application maps to two bats files" {
50-
echo "packages/apps/kubernetes/values.yaml" > $TMPDIR/diff
51-
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
52-
echo $output | grep -q "kubernetes-latest"
53-
echo $output | grep -q "kubernetes-previous"
69+
tmp=$(mktemp -d)
70+
trap 'rm -rf "$tmp"' EXIT
71+
cp -r packages/core/platform/sources "$tmp/sources"
72+
echo "packages/apps/kubernetes/values.yaml" > "$tmp/diff"
73+
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
74+
echo "$output" | grep -q "kubernetes-latest"
75+
echo "$output" | grep -q "kubernetes-previous"
5476
}
5577

5678
@test "dashboards-only diff selects nothing (path is plural)" {
57-
echo "dashboards/gpu/gpu-fleet.json" > $TMPDIR/diff
58-
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
59-
[ "$status" -eq 0 ]
60-
[ -z "$output" ]
79+
tmp=$(mktemp -d)
80+
trap 'rm -rf "$tmp"' EXIT
81+
cp -r packages/core/platform/sources "$tmp/sources"
82+
echo "dashboards/gpu/gpu-fleet.json" > "$tmp/diff"
83+
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
84+
[ -z "$output" ]
6185
}
6286

6387
@test "shared E2E helper script triggers full suite" {
64-
echo "hack/e2e-apps/run-kubernetes.sh" > $TMPDIR/diff
65-
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
66-
[ "$(echo $output | wc -w)" -gt 5 ]
88+
tmp=$(mktemp -d)
89+
trap 'rm -rf "$tmp"' EXIT
90+
cp -r packages/core/platform/sources "$tmp/sources"
91+
echo "hack/e2e-apps/run-kubernetes.sh" > "$tmp/diff"
92+
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
93+
[ "$(echo "$output" | wc -w)" -gt 5 ]
6794
}
6895

6996
@test "install bats triggers full suite" {
70-
echo "hack/e2e-install-cozystack.bats" > $TMPDIR/diff
71-
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
72-
[ "$(echo $output | wc -w)" -gt 5 ]
97+
tmp=$(mktemp -d)
98+
trap 'rm -rf "$tmp"' EXIT
99+
cp -r packages/core/platform/sources "$tmp/sources"
100+
echo "hack/e2e-install-cozystack.bats" > "$tmp/diff"
101+
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
102+
[ "$(echo "$output" | wc -w)" -gt 5 ]
73103
}
74104

75105
@test "per-app bats edit selects only that app, never escalates" {
76-
echo "hack/e2e-apps/redis.bats" > $TMPDIR/diff
77-
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
78-
[ "$status" -eq 0 ]
79-
[ "$output" = "redis" ]
106+
tmp=$(mktemp -d)
107+
trap 'rm -rf "$tmp"' EXIT
108+
cp -r packages/core/platform/sources "$tmp/sources"
109+
echo "hack/e2e-apps/redis.bats" > "$tmp/diff"
110+
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
111+
[ "$output" = "redis" ]
80112
}
81113

82114
@test "release-e2e workflow change triggers full suite" {
83-
echo ".github/workflows/release-e2e.yaml" > $TMPDIR/diff
84-
run hack/select-e2e.sh $TMPDIR/diff $TMPDIR/sources
85-
[ "$(echo $output | wc -w)" -gt 5 ]
86-
}
87-
88-
teardown() {
89-
rm -rf $TMPDIR
115+
tmp=$(mktemp -d)
116+
trap 'rm -rf "$tmp"' EXIT
117+
cp -r packages/core/platform/sources "$tmp/sources"
118+
echo ".github/workflows/release-e2e.yaml" > "$tmp/diff"
119+
output=$(hack/select-e2e.sh "$tmp/diff" "$tmp/sources")
120+
[ "$(echo "$output" | wc -w)" -gt 5 ]
90121
}

0 commit comments

Comments
 (0)