Skip to content

Commit eb1c49d

Browse files
authored
acceptance: make contains.py fail the test on a failed assertion (#5466)
`contains.py` (#3345) printed `contains error:` to stderr but exited 0, so a failed assertion got baked into the golden output instead of failing the test. It now exits non-zero, so under the harness's `bash -euo pipefail` the script aborts. This surfaced a stale assertion in `bundle/state/state_present` (serial asserted as `11`/`12`, but it's been `13` since the test was added); `selftest/contains` wraps its failing cases in `errcode` so the script still runs to completion. This pull request and its description were written by Isaac.
1 parent f725fb5 commit eb1c49d

5 files changed

Lines changed: 19 additions & 7 deletions

File tree

acceptance/bin/contains.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
must_find.append(arg)
1111

1212
found = set()
13+
failed = False
1314

1415
for line in sys.stdin:
1516
sys.stdout.write(line)
@@ -19,9 +20,16 @@
1920
for t in must_not_find:
2021
if t in line:
2122
sys.stderr.write(f"contains error: {t!r} was not expected: {line.strip()!r}\n")
23+
failed = True
2224

2325
sys.stdout.flush()
2426

2527
not_found = set(must_find) - found
2628
for item in sorted(not_found):
2729
sys.stderr.write(f"contains error: {item!r} not found in the output.\n")
30+
failed = True
31+
32+
# Exit non-zero so a failed assertion aborts the script (set -e -o pipefail)
33+
# instead of silently baking the error line into the expected output.
34+
if failed:
35+
sys.exit(1)

acceptance/bundle/state/state_present/output.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ Deployment complete!
7171
>>> print_state.py
7272
3
7373
13
74-
contains error: '11' not found in the output.
7574

7675
>>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy
7776
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
@@ -92,7 +91,6 @@ Deployment complete!
9291
>>> print_state.py
9392
3
9493
13
95-
contains error: '12' not found in the output.
9694

9795
>>> DATABRICKS_BUNDLE_ENGINE= [CLI] bundle debug states
9896
[TEST_TMP_DIR]/.databricks/bundle/default/terraform/terraform.tfstate: local terraform state serial=3 lineage="test-lineage"

acceptance/bundle/state/state_present/script

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle destroy --auto-approve
2929
rm out.requests.txt
3030
trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy
3131
trace print_requests.py //api/2.1/unity-catalog/schemas | jq '.headers["User-Agent"][0]' | contains.py 'engine/direct' '!terraform' '!tf-provider'
32-
trace print_state.py | jq .serial | contains.py "11"
32+
trace print_state.py | jq .serial | contains.py "13"
3333

3434
trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy
3535
#trace print_requests.py --get //api/2.1/unity-catalog/schemas | jq '.headers["User-Agent"][0]' | contains.py 'engine/direct' '!terraform' '!tf-provider'
3636

3737
trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle deploy
3838
trace print_requests.py --get //api/2.1/unity-catalog/schemas | jq '.headers["User-Agent"][0]' | contains.py 'engine/direct' '!terraform' '!tf-provider'
39-
trace print_state.py | jq .serial | contains.py "12"
39+
trace print_state.py | jq .serial | contains.py "13"
4040

4141
trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle debug states
4242
trace DATABRICKS_BUNDLE_ENGINE= $CLI bundle debug states --force-pull

acceptance/selftest/contains/output.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
Hello world
55
contains error: 'not_found' not found in the output.
66

7+
Exit code: 1
8+
79
=== This should complain about not_found not found
810
>>> musterr python3 ./failure.py
911
Failed script
1012
contains error: 'not_found' not found in the output.
1113

14+
Exit code: 1
15+
1216
=== This should not complain
1317
>>> python3 ./success.py
1418
Hello world
@@ -22,6 +26,8 @@ Failed script
2226
Hello world
2327
contains error: 'Hello' was not expected: 'Hello world'
2428

29+
Exit code: 1
30+
2531
=== This should not complain
2632
>>> python3 ./success.py
2733
Hello world
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
title "This should complain about not_found not found"
2-
trace python3 ./success.py | contains.py not_found
2+
trace python3 ./success.py | errcode contains.py not_found
33

44
title "This should complain about not_found not found"
5-
trace musterr python3 ./failure.py | contains.py not_found
5+
trace musterr python3 ./failure.py | errcode contains.py not_found
66

77
title "This should not complain"
88
trace python3 ./success.py | contains.py world Hello
@@ -11,7 +11,7 @@ title "This should not complain"
1111
trace musterr python3 ./failure.py | contains.py Failed
1212

1313
title "This should complain about Hello present in output"
14-
trace python3 ./success.py | contains.py !Hello
14+
trace python3 ./success.py | errcode contains.py !Hello
1515

1616
title "This should not complain"
1717
trace python3 ./success.py | contains.py !not_found

0 commit comments

Comments
 (0)