Skip to content

Commit 5963b41

Browse files
authored
Improve testserver; use testserver instead of hard-coded responses (#4257)
## Changes ### Acceptance test runner - Provision default cluster and TEST_DEFAULT_CLUSTER_ID in testserver. ### testserver - Update dashboards to set ParentPath. - Update experiments and model serving endpoints to match real responses. - Pre-provision home directories. - Pre-provision SQL ware house ### Tests - Use $UNIQUE_NAME instead of uuid function in tests. - Use testserver instead of hard-coded responses. ## Why Tests that hard code responses in test.toml are harder to evolve.
1 parent 819274c commit 5963b41

48 files changed

Lines changed: 235 additions & 330 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

acceptance/acceptance_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/databricks/cli/internal/testutil"
3131
"github.com/databricks/cli/libs/auth"
3232
"github.com/databricks/cli/libs/testdiff"
33+
"github.com/databricks/cli/libs/testserver"
3334
"github.com/databricks/cli/libs/utils"
3435
"github.com/stretchr/testify/require"
3536
)
@@ -152,6 +153,7 @@ func TestInprocessMode(t *testing.T) {
152153
func setReplsForTestEnvVars(t *testing.T, repls *testdiff.ReplacementsContext) {
153154
envVars := []string{
154155
"TEST_DEFAULT_WAREHOUSE_ID",
156+
"TEST_DEFAULT_CLUSTER_ID",
155157
"TEST_INSTANCE_POOL_ID",
156158
}
157159
for _, envVar := range envVars {
@@ -244,7 +246,10 @@ func testAccept(t *testing.T, inprocessMode bool, singleTest string) int {
244246
if cloudEnv == "" {
245247
internal.StartDefaultServer(t, LogRequests)
246248
if os.Getenv("TEST_DEFAULT_WAREHOUSE_ID") == "" {
247-
t.Setenv("TEST_DEFAULT_WAREHOUSE_ID", "8ec9edc1-db0c-40df-af8d-7580020fe61e")
249+
t.Setenv("TEST_DEFAULT_WAREHOUSE_ID", testserver.TestDefaultWarehouseId)
250+
}
251+
if os.Getenv("TEST_DEFAULT_CLUSTER_ID") == "" {
252+
t.Setenv("TEST_DEFAULT_CLUSTER_ID", testserver.TestDefaultClusterId)
248253
}
249254
}
250255

acceptance/bundle/deployment/bind/cluster/output.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

2-
>>> [CLI] clusters get [CLUSTER-ID]
2+
>>> [CLI] clusters get [TEST_DEFAULT_CLUSTER_ID]
33
{
44
"cluster_name": "DEFAULT Test Cluster"
55
}
66

7-
>>> [CLI] bundle deployment bind cluster1 [CLUSTER-ID] --auto-approve
7+
>>> [CLI] bundle deployment bind cluster1 [TEST_DEFAULT_CLUSTER_ID] --auto-approve
88
Updating deployment state...
9-
Successfully bound cluster with an id '[CLUSTER-ID]'
9+
Successfully bound cluster with an id '[TEST_DEFAULT_CLUSTER_ID]'
1010
Run 'bundle deploy' to deploy changes to your workspace
1111

1212
>>> [CLI] bundle deployment unbind cluster1
Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
11
Local = true
22
Cloud = true
33
RequiresCluster = true
4-
5-
Ignore = [
6-
"databricks.yml",
7-
]
8-
9-
[[Repls]]
10-
Old = "[0-9]{4}-[0-9]{6}-[0-9a-z]{8}"
11-
New = "[CLUSTER-ID]"
12-
13-
[[Server]]
14-
Pattern = "GET /api/2.1/clusters/get"
15-
Response.Body = '''
16-
{
17-
"cluster_name": "DEFAULT Test Cluster"
18-
}
19-
'''

acceptance/bundle/deployment/bind/dashboard/output.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ Deployment complete!
1212

1313
>>> [CLI] lakeview get [DASHBOARD_ID]
1414
{
15-
"display_name": "test dashboard [UUID]",
15+
"display_name": "test dashboard [UNIQUE_NAME]",
1616
"lifecycle_state": "ACTIVE",
17-
"path": "/Users/[USERNAME]/test dashboard [UUID].lvdash.json",
1817
"parent_path": "/Users/[USERNAME]",
18+
"path": "/Users/[USERNAME]/test dashboard [UNIQUE_NAME].lvdash.json",
1919
"serialized_dashboard": {
2020
"pages": [
2121
{
22-
"name": "02724bf2",
2322
"displayName": "Page One",
23+
"name": "02724bf2",
2424
"pageType": "PAGE_TYPE_CANVAS"
2525
}
2626
]
@@ -38,15 +38,15 @@ Destroy complete!
3838

3939
>>> [CLI] lakeview get [DASHBOARD_ID]
4040
{
41-
"display_name": "test dashboard [UUID]",
41+
"display_name": "test dashboard [UNIQUE_NAME]",
4242
"lifecycle_state": "ACTIVE",
43-
"path": "/Users/[USERNAME]/test dashboard [UUID].lvdash.json",
4443
"parent_path": "/Users/[USERNAME]",
44+
"path": "/Users/[USERNAME]/test dashboard [UNIQUE_NAME].lvdash.json",
4545
"serialized_dashboard": {
4646
"pages": [
4747
{
48-
"name": "02724bf2",
4948
"displayName": "Page One",
49+
"name": "02724bf2",
5050
"pageType": "PAGE_TYPE_CANVAS"
5151
}
5252
]

acceptance/bundle/deployment/bind/dashboard/recreation/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ Deployment complete!
2626

2727
>>> [CLI] lakeview get [DASHBOARD_ID]
2828
{
29-
"display_name": "test dashboard [UUID]",
29+
"display_name": "test dashboard [UNIQUE_NAME]",
3030
"lifecycle_state": "ACTIVE"
3131
}

acceptance/bundle/deployment/bind/dashboard/recreation/script

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
DASHBOARD_DISPLAY_NAME="test dashboard $(uuid)"
2-
if [ -z "$CLOUD_ENV" ]; then
3-
DASHBOARD_DISPLAY_NAME="test dashboard 6260d50f-e8ff-4905-8f28-812345678903" # use hard-coded uuid when running locally
4-
export TEST_DEFAULT_WAREHOUSE_ID="warehouse-1234"
5-
fi
1+
DASHBOARD_DISPLAY_NAME="test dashboard $UNIQUE_NAME"
62

73
export DASHBOARD_DISPLAY_NAME
84
envsubst < databricks.yml.tmpl > databricks.yml

acceptance/bundle/deployment/bind/dashboard/script

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
DASHBOARD_DISPLAY_NAME="test dashboard $(uuid)"
2-
if [ -z "$CLOUD_ENV" ]; then
3-
DASHBOARD_DISPLAY_NAME="test dashboard 6260d50f-e8ff-4905-8f28-812345678903" # use hard-coded uuid when running locally
4-
export TEST_DEFAULT_WAREHOUSE_ID="warehouse-1234"
5-
fi
1+
DASHBOARD_DISPLAY_NAME="test dashboard $UNIQUE_NAME"
62

73
export DASHBOARD_DISPLAY_NAME
84
envsubst < databricks.yml.tmpl > databricks.yml
@@ -19,11 +15,11 @@ trace $CLI bundle deployment bind dashboard1 "${DASHBOARD_ID}" --auto-approve
1915

2016
trace $CLI bundle deploy
2117

22-
trace $CLI lakeview get "${DASHBOARD_ID}" | jq '{display_name, lifecycle_state, path, parent_path, serialized_dashboard} | .serialized_dashboard |= fromjson'
18+
trace $CLI lakeview get "${DASHBOARD_ID}" | jq --sort-keys '{display_name, lifecycle_state, path, parent_path, serialized_dashboard} | .serialized_dashboard |= fromjson'
2319

2420
trace $CLI bundle deployment unbind dashboard1
2521

2622
trace $CLI bundle destroy --auto-approve
2723

2824
# Read the pre-defined dashboard again (expecting it still exists and is not deleted):
29-
trace $CLI lakeview get "${DASHBOARD_ID}" | jq '{display_name, lifecycle_state, path, parent_path, serialized_dashboard} | .serialized_dashboard |= fromjson'
25+
trace $CLI lakeview get "${DASHBOARD_ID}" | jq --sort-keys '{display_name, lifecycle_state, path, parent_path, serialized_dashboard} | .serialized_dashboard |= fromjson'

acceptance/bundle/deployment/bind/dashboard/test.toml

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,6 @@ Local = true
22
Cloud = true
33
RequiresWarehouse = true
44

5-
Ignore = [
6-
"databricks.yml",
7-
]
8-
95
[[Repls]]
106
Old = "[0-9a-f]{32}"
117
New = "[DASHBOARD_ID]"
12-
13-
[[Server]]
14-
Pattern = "POST /api/2.0/lakeview/dashboards"
15-
Response.Body = '''
16-
{
17-
"dashboard_id":"1234567890abcdef1234567890abcdef"
18-
}
19-
'''
20-
21-
[[Server]]
22-
Pattern = "POST /api/2.0/lakeview/dashboards/{dashboard_id}/published"
23-
24-
[[Server]]
25-
Pattern = "PATCH /api/2.0/lakeview/dashboards/{dashboard_id}"
26-
27-
[[Server]]
28-
Pattern = "GET /api/2.0/lakeview/dashboards/{dashboard_id}"
29-
Response.Body = '''
30-
{
31-
"dashboard_id":"1234567890abcdef1234567890abcdef",
32-
"display_name": "test dashboard 6260d50f-e8ff-4905-8f28-812345678903",
33-
"lifecycle_state": "ACTIVE",
34-
"path": "/Users/[USERNAME]/test dashboard [UUID].lvdash.json",
35-
"parent_path": "/Users/tester@databricks.com",
36-
"serialized_dashboard": "{\"pages\":[{\"name\":\"02724bf2\",\"displayName\":\"Page One\",\"pageType\":\"PAGE_TYPE_CANVAS\"}]}"
37-
}
38-
'''
39-
40-
[[Server]]
41-
Pattern = "DELETE /api/2.0/lakeview/dashboards/{dashboard_id}"

acceptance/bundle/deployment/bind/experiment/output.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Updating deployment state...
1212
Deployment complete!
1313

1414
=== Read the pre-defined experiment: {
15-
"name": "/Users/[USERNAME]/test-experiment[UUID]",
15+
"name": "/Users/[USERNAME]/test-experiment[UNIQUE_NAME]",
1616
"lifecycle_stage": "active"
1717
}
1818

@@ -24,7 +24,7 @@ Deleting files...
2424
Destroy complete!
2525

2626
=== Read the pre-defined experiment again (expecting it still exists and is not deleted): {
27-
"name": "/Users/[USERNAME]/test-experiment[UUID]",
27+
"name": "/Users/[USERNAME]/test-experiment[UNIQUE_NAME]",
2828
"lifecycle_stage": "active"
2929
}
3030

acceptance/bundle/deployment/bind/experiment/script

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ title "Bind experiment test:"
33
title "Substitute variables in the template"
44

55
# double slash at the start prevents Windows to apply replacements to the path
6-
EXPERIMENT_NAME="//Workspace/Users/${CURRENT_USER_NAME}/test-experiment$(uuid)"
7-
if [ -z "$CLOUD_ENV" ]; then
8-
EXPERIMENT_NAME="//Workspace/Users/${CURRENT_USER_NAME}/test-experiment6260d50f-e8ff-4905-8f28-812345678903" # use hard-coded uuid when running locally
9-
fi
6+
EXPERIMENT_NAME="//Workspace/Users/${CURRENT_USER_NAME}/test-experiment$UNIQUE_NAME"
107
export EXPERIMENT_NAME
118
envsubst < databricks.yml.tmpl > databricks.yml
129

0 commit comments

Comments
 (0)