|
1 | 1 | #!/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 | +# ----------------------------------------------------------------------------- |
7 | 13 |
|
8 | 14 | @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" ] |
13 | 21 | } |
14 | 22 |
|
15 | 23 | @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 |
26 | 38 | } |
27 | 39 |
|
28 | 40 | @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 ] |
34 | 48 | } |
35 | 49 |
|
36 | 50 | @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 ] |
40 | 57 | } |
41 | 58 |
|
42 | 59 | @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" ] |
47 | 66 | } |
48 | 67 |
|
49 | 68 | @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" |
54 | 76 | } |
55 | 77 |
|
56 | 78 | @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" ] |
61 | 85 | } |
62 | 86 |
|
63 | 87 | @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 ] |
67 | 94 | } |
68 | 95 |
|
69 | 96 | @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 ] |
73 | 103 | } |
74 | 104 |
|
75 | 105 | @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" ] |
80 | 112 | } |
81 | 113 |
|
82 | 114 | @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 ] |
90 | 121 | } |
0 commit comments