Skip to content

Commit 93b59f2

Browse files
denikclaude
andauthored
Add invariant tests (#4326)
## Changes Add a new kind of test - invariant test for DABs (a subtype of acceptance test). Invariant tests are acceptance tests that can be run against many configs to check for certain properties. Unlike regular acceptance tests full output is not recorded, unless the condition is not met. In this PR there is one invariant test added - no_drift, that checks that there are no actions planned after successful deploy. If that's not the case, the test will dump full JSON plan to the output. ## Why Simplify resource implementation testing - implementors only need to provide a config to get all invariants check. With no_drift in particular, we've had several cases where this condition is not met and it's still the case for some configurations of permissions and grants. It's also going to become more important as we replace "server_side_default" with something more precise. The other use of invariant tests is fuzzing - since they work on any config, they can be used on randomly generated configs to find bugs. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5375382 commit 93b59f2

28 files changed

+337
-0
lines changed

acceptance/bin/verify_no_drift.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Check that all actions in plan are "skip".
4+
"""
5+
6+
import sys
7+
import json
8+
import pprint
9+
10+
11+
def check_plan(path):
12+
with open(path) as fobj:
13+
raw = fobj.read()
14+
15+
changes_detected = 0
16+
17+
try:
18+
data = json.loads(raw)
19+
for key, value in data["plan"].items():
20+
action = value.get("action")
21+
if action != "skip":
22+
print(f"Unexpected {action=} for {key}")
23+
changes_detected += 1
24+
except Exception:
25+
print(raw, flush=True)
26+
raise
27+
28+
if changes_detected:
29+
print(raw, flush=True)
30+
sys.exit(10)
31+
32+
33+
def main():
34+
for path in sys.argv[1:]:
35+
check_plan(path)
36+
37+
38+
if __name__ == "__main__":
39+
main()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Invariant tests are acceptance tests that can be run against many configs to check for certain properties.
2+
Unlike regular acceptance tests full output is not recorded, unless the condition is not met. For example,
3+
no_drift test checks that there are no actions planned after successful deploy. If that's not the case, the
4+
test will dump full JSON plan to the output.
5+
6+
In order to add a new test, add a config to configs/ and include it in test.toml.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
bundle:
2+
name: test-bundle-$UNIQUE_NAME
3+
4+
resources:
5+
alerts:
6+
foo:
7+
warehouse_id: $TEST_DEFAULT_WAREHOUSE_ID
8+
display_name: test-alert-$UNIQUE_NAME
9+
file_path: ./alert.dbalert.json
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
bundle:
2+
name: test-bundle-$UNIQUE_NAME
3+
4+
resources:
5+
apps:
6+
foo:
7+
name: app-$UNIQUE_NAME
8+
source_code_path: ./app
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
bundle:
2+
name: test-bundle-$UNIQUE_NAME
3+
4+
resources:
5+
clusters:
6+
foo:
7+
cluster_name: test-cluster-$UNIQUE_NAME
8+
spark_version: 13.3.x-scala2.12
9+
node_type_id: i3.xlarge
10+
num_workers: 1
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
bundle:
2+
name: test-bundle-$UNIQUE_NAME
3+
4+
resources:
5+
dashboards:
6+
foo:
7+
warehouse_id: $TEST_DEFAULT_WAREHOUSE_ID
8+
display_name: test-dashboard-$UNIQUE_NAME
9+
file_path: ./dashboard.lvdash.json
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
bundle:
2+
name: test-bundle-$UNIQUE_NAME
3+
4+
resources:
5+
database_instances:
6+
instance1:
7+
name: test-db-instance-$UNIQUE_NAME
8+
capacity: CU_1
9+
10+
database_catalogs:
11+
foo:
12+
database_instance_name: ${resources.database_instances.instance1.name}
13+
database_name: test_db
14+
name: test-catalog-$UNIQUE_NAME
15+
create_database_if_not_exists: true
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
bundle:
2+
name: test-bundle-$UNIQUE_NAME
3+
4+
resources:
5+
database_instances:
6+
foo:
7+
name: test-db-instance-$UNIQUE_NAME
8+
capacity: CU_1
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bundle:
2+
name: test-bundle-$UNIQUE_NAME
3+
4+
resources:
5+
experiments:
6+
foo:
7+
name: /Users/$CURRENT_USER_NAME/test-experiment-$UNIQUE_NAME
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bundle:
2+
name: test-bundle-$UNIQUE_NAME
3+
4+
resources:
5+
jobs:
6+
foo:
7+
name: test-job-$UNIQUE_NAME

0 commit comments

Comments
 (0)