Skip to content

Commit 0769627

Browse files
authored
acc: add tests for user input for internal & readonly fields (#3491)
## Changes New tests that cover: - users supplying id & url fields. - users referencing url from another resource. ## Why These should be rejected. In direct implementation I'm using typed struct access to reject this based on tag, these tests record the behaviour.
1 parent 911f36d commit 0769627

28 files changed

+398
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resources:
2+
jobs:
3+
foo:
4+
# This should not be allowed, id is bundle:readonly field
5+
id: 123
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Local = true
2+
Cloud = false
3+
4+
[EnvMatrix]
5+
DATABRICKS_CLI_DEPLOYMENT = ["terraform", "direct-exp"]
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
2+
>>> [CLI] bundle validate
3+
Name: test-bundle
4+
Target: default
5+
Workspace:
6+
User: [USERNAME]
7+
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
8+
9+
Validation OK!
10+
11+
>>> [CLI] bundle validate -o json
12+
{
13+
"jobs": {
14+
"foo": {
15+
"deployment": {
16+
"kind": "BUNDLE",
17+
"metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json"
18+
},
19+
"edit_mode": "UI_LOCKED",
20+
"format": "MULTI_TASK",
21+
"id": "123",
22+
"max_concurrent_runs": 1,
23+
"name": "Untitled",
24+
"permissions": [],
25+
"queue": {
26+
"enabled": true
27+
}
28+
}
29+
}
30+
}
31+
32+
>>> [CLI] bundle plan
33+
create jobs.foo
34+
35+
>>> [CLI] bundle deploy
36+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
37+
Deploying resources...
38+
Updating deployment state...
39+
Deployment complete!
40+
41+
>>> print_requests
42+
{
43+
"body": {
44+
"deployment": {
45+
"kind": "BUNDLE",
46+
"metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json"
47+
},
48+
"edit_mode": "UI_LOCKED",
49+
"format": "MULTI_TASK",
50+
"max_concurrent_runs": 1,
51+
"name": "Untitled",
52+
"queue": {
53+
"enabled": true
54+
}
55+
},
56+
"method": "POST",
57+
"path": "/api/2.2/jobs/create"
58+
}
59+
60+
>>> [CLI] bundle summary
61+
Name: test-bundle
62+
Target: default
63+
Workspace:
64+
User: [USERNAME]
65+
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
66+
Resources:
67+
Jobs:
68+
foo:
69+
Name: Untitled
70+
URL: [DATABRICKS_URL]/jobs/[NUMID]?o=[NUMID]
71+
72+
>>> [CLI] bundle destroy --auto-approve
73+
The following resources will be deleted:
74+
delete job foo
75+
76+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
77+
78+
Deleting files...
79+
Destroy complete!
80+
81+
>>> print_requests
82+
{
83+
"body": {
84+
"job_id": [NUMID]
85+
},
86+
"method": "POST",
87+
"path": "/api/2.2/jobs/delete"
88+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
print_requests() {
2+
jq --sort-keys 'select(.method != "GET" and (.path | contains("/jobs")))' < out.requests.txt
3+
rm out.requests.txt
4+
}
5+
6+
trace $CLI bundle validate
7+
trace $CLI bundle validate -o json | jq .resources
8+
trace $CLI bundle plan
9+
trace $CLI bundle deploy
10+
trace print_requests
11+
trace $CLI bundle summary
12+
trace $CLI bundle destroy --auto-approve
13+
trace print_requests
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RecordRequests = true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Badness = "configs with id and url should be rejected"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resources:
2+
jobs:
3+
foo:
4+
# This should not be allowed, url is internal field
5+
url: my_job_url
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Local = true
2+
Cloud = false
3+
4+
[EnvMatrix]
5+
DATABRICKS_CLI_DEPLOYMENT = ["terraform", "direct-exp"]
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
2+
>>> [CLI] bundle validate
3+
Name: test-bundle
4+
Target: default
5+
Workspace:
6+
User: [USERNAME]
7+
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
8+
9+
Validation OK!
10+
11+
>>> [CLI] bundle validate -o json
12+
{
13+
"jobs": {
14+
"foo": {
15+
"deployment": {
16+
"kind": "BUNDLE",
17+
"metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json"
18+
},
19+
"edit_mode": "UI_LOCKED",
20+
"format": "MULTI_TASK",
21+
"max_concurrent_runs": 1,
22+
"name": "Untitled",
23+
"permissions": [],
24+
"queue": {
25+
"enabled": true
26+
},
27+
"url": "my_job_url"
28+
}
29+
}
30+
}
31+
32+
>>> [CLI] bundle plan
33+
create jobs.foo
34+
35+
>>> [CLI] bundle deploy
36+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
37+
Deploying resources...
38+
Updating deployment state...
39+
Deployment complete!
40+
41+
>>> print_requests
42+
{
43+
"body": {
44+
"deployment": {
45+
"kind": "BUNDLE",
46+
"metadata_file_path": "/Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/metadata.json"
47+
},
48+
"edit_mode": "UI_LOCKED",
49+
"format": "MULTI_TASK",
50+
"max_concurrent_runs": 1,
51+
"name": "Untitled",
52+
"queue": {
53+
"enabled": true
54+
}
55+
},
56+
"method": "POST",
57+
"path": "/api/2.2/jobs/create"
58+
}
59+
60+
>>> [CLI] bundle summary
61+
Name: test-bundle
62+
Target: default
63+
Workspace:
64+
User: [USERNAME]
65+
Path: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
66+
Resources:
67+
Jobs:
68+
foo:
69+
Name: Untitled
70+
URL: [DATABRICKS_URL]/jobs/[NUMID]?o=[NUMID]
71+
72+
>>> [CLI] bundle destroy --auto-approve
73+
The following resources will be deleted:
74+
delete job foo
75+
76+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default
77+
78+
Deleting files...
79+
Destroy complete!
80+
81+
>>> print_requests
82+
{
83+
"body": {
84+
"job_id": [NUMID]
85+
},
86+
"method": "POST",
87+
"path": "/api/2.2/jobs/delete"
88+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
print_requests() {
2+
jq --sort-keys 'select(.method != "GET" and (.path | contains("/jobs")))' < out.requests.txt
3+
rm out.requests.txt
4+
}
5+
6+
trace $CLI bundle validate
7+
trace $CLI bundle validate -o json | jq .resources
8+
trace $CLI bundle plan
9+
trace $CLI bundle deploy
10+
trace print_requests
11+
trace $CLI bundle summary
12+
trace $CLI bundle destroy --auto-approve
13+
trace print_requests

0 commit comments

Comments
 (0)