Skip to content

Commit f00b846

Browse files
authored
Convert TestDashboards to an acceptance test (#2918)
## Why <!-- Why are these changes needed? Provide the context that the reviewer might be missing. For example, were there any decisions behind the change that are not reflected in the code itself? --> One change in the series of changes for converting integration tests into acceptance tests. This will allow for easier testing of various backing solutions for bundle deployment
1 parent 75d7243 commit f00b846

9 files changed

Lines changed: 112 additions & 114 deletions

File tree

integration/bundle/bundles/dashboards/template/dashboard.lvdash.json renamed to acceptance/bundle/deploy/dashboard/detect-change/dashboard.lvdash.json

File renamed without changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
bundle:
2+
name: dashboards
3+
4+
workspace:
5+
root_path: ~/.bundle/$UNIQUE_NAME
6+
7+
resources:
8+
dashboards:
9+
file_reference:
10+
display_name: test-dashboard-$UNIQUE_NAME
11+
file_path: ./dashboard.lvdash.json
12+
warehouse_id: $TEST_DEFAULT_WAREHOUSE_ID
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
>>> [CLI] bundle deploy
3+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files...
4+
Deploying resources...
5+
Updating deployment state...
6+
Deployment complete!
7+
8+
=== Assert that the dashboard exists at the expected path and is, indeed, a dashboard:
9+
>>> [CLI] workspace get-status /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/resources/test-dashboard-[UNIQUE_NAME].lvdash.json
10+
{
11+
"object_type": "DASHBOARD",
12+
"path": "/Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/resources/test-dashboard-[UNIQUE_NAME].lvdash.json"
13+
}
14+
15+
=== Load the dashboard by its ID and confirm its display name: {
16+
"display_name": "test-dashboard-[UNIQUE_NAME]",
17+
"serialized_dashboard": "{\"pages\":[{\"name\":\"fdd21a3c\",\"displayName\":\"New Page\",\"layout\":[{\"widget\":{\"name\":\"82eb9107\",\"textbox_spec\":\"# I'm a title\"},\"position\":{\"x\":0,\"y\":0,\"width\":6,\"height\":2}},{\"widget\":{\"name\":\"ffa6de4f\",\"textbox_spec\":\"Text\"},\"position\":{\"x\":0,\"y\":2,\"width\":6,\"height\":2}}],\"pageType\":\"PAGE_TYPE_CANVAS\"}]}"
18+
}
19+
20+
=== Make an out of band modification to the dashboard and confirm that it is detected:
21+
{
22+
"lifecycle_state": "ACTIVE"
23+
}
24+
25+
=== Try to redeploy the bundle and confirm that the out of band modification is detected:
26+
>>> errcode [CLI] bundle deploy
27+
Error: dashboard "file_reference" has been modified remotely
28+
at resources.dashboards.file_reference
29+
in databricks.yml:10:7
30+
31+
This dashboard has been modified remotely since the last bundle deployment.
32+
These modifications are untracked and will be overwritten on deploy.
33+
34+
Make sure that the local dashboard definition matches what you intend to deploy
35+
before proceeding with the deployment.
36+
37+
Run `databricks bundle deploy --force` to bypass this error.
38+
39+
40+
Exit code: 1
41+
42+
=== Redeploy the bundle with the --force flag and confirm that the out of band modification is ignored:
43+
>>> errcode [CLI] bundle deploy --force
44+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]/files...
45+
Deploying resources...
46+
Updating deployment state...
47+
Deployment complete!
48+
49+
>>> [CLI] bundle destroy --auto-approve
50+
The following resources will be deleted:
51+
delete dashboard file_reference
52+
53+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/[UNIQUE_NAME]
54+
55+
Deleting files...
56+
Destroy complete!
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
envsubst < databricks.yml.tmpl > databricks.yml
2+
3+
cleanup() {
4+
trace $CLI bundle destroy --auto-approve
5+
}
6+
trap cleanup EXIT
7+
8+
trace $CLI bundle deploy
9+
10+
title "Assert that the dashboard exists at the expected path and is, indeed, a dashboard:"
11+
RESOURCE_PATH=$($CLI bundle validate -o json | jq -r '.workspace.resource_path')
12+
DASHBOARD_PATH="${RESOURCE_PATH}/test-dashboard-${UNIQUE_NAME}.lvdash.json"
13+
trace $CLI workspace get-status "${DASHBOARD_PATH}" | jq '{object_type,path}'
14+
15+
title "Load the dashboard by its ID and confirm its display name: "
16+
DASHBOARD_ID=$($CLI bundle summary --output json | jq -r '.resources.dashboards.file_reference.id')
17+
$CLI lakeview get $DASHBOARD_ID | jq '{display_name,serialized_dashboard}'
18+
19+
title "Make an out of band modification to the dashboard and confirm that it is detected:\n"
20+
RESOURCE_ID=$($CLI workspace get-status "${DASHBOARD_PATH}" | jq -r '.resource_id')
21+
DASHBOARD_JSON=$($CLI bundle summary --output json | jq '{serialized_dashboard: .resources.dashboards.file_reference.serialized_dashboard}')
22+
$CLI lakeview update "${RESOURCE_ID}" --json "${DASHBOARD_JSON}" | jq '{lifecycle_state}'
23+
24+
title "Try to redeploy the bundle and confirm that the out of band modification is detected:"
25+
trace errcode $CLI bundle deploy
26+
27+
title "Redeploy the bundle with the --force flag and confirm that the out of band modification is ignored:"
28+
trace errcode $CLI bundle deploy --force
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Local = false
2+
Cloud = true
3+
4+
Ignore = [
5+
"databricks.yml",
6+
]
7+
8+
[Env]
9+
# MSYS2 automatically converts absolute paths like /Users/$username/$UNIQUE_NAME to
10+
# C:/Program Files/Git/Users/$username/UNIQUE_NAME before passing it to the CLI
11+
# Setting this environment variable prevents that conversion on windows.
12+
MSYS_NO_PATHCONV = "1"
13+
14+
[[Repls]]
15+
Old = "[0-9a-z]{16,}"
16+
New = "[ALPHANUMID]"

integration/bundle/bundles/dashboards/databricks_template_schema.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

integration/bundle/bundles/dashboards/template/databricks.yml.tmpl

Lines changed: 0 additions & 12 deletions
This file was deleted.

integration/bundle/dashboards_test.go

Lines changed: 0 additions & 62 deletions
This file was deleted.

integration/bundle/helpers_test.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"path/filepath"
99
"strings"
1010

11-
"github.com/databricks/cli/bundle"
1211
"github.com/databricks/cli/internal/testcli"
1312
"github.com/databricks/cli/internal/testutil"
1413
"github.com/databricks/cli/libs/cmdctx"
@@ -72,40 +71,13 @@ func validateBundle(t testutil.TestingT, ctx context.Context, path string) ([]by
7271
return stdout.Bytes(), err
7372
}
7473

75-
func mustValidateBundle(t testutil.TestingT, ctx context.Context, path string) []byte {
76-
data, err := validateBundle(t, ctx, path)
77-
require.NoError(t, err)
78-
return data
79-
}
80-
81-
func unmarshalConfig(t testutil.TestingT, data []byte) *bundle.Bundle {
82-
bundle := &bundle.Bundle{}
83-
err := json.Unmarshal(data, &bundle.Config)
84-
require.NoError(t, err)
85-
return bundle
86-
}
87-
8874
func deployBundle(t testutil.TestingT, ctx context.Context, path string) {
8975
ctx = env.Set(ctx, "BUNDLE_ROOT", path)
9076
c := testcli.NewRunner(t, ctx, "bundle", "deploy", "--force-lock", "--auto-approve")
9177
_, _, err := c.Run()
9278
require.NoError(t, err)
9379
}
9480

95-
func deployBundleWithArgsErr(t testutil.TestingT, ctx context.Context, path string, args ...string) (string, string, error) {
96-
ctx = env.Set(ctx, "BUNDLE_ROOT", path)
97-
args = append([]string{"bundle", "deploy"}, args...)
98-
c := testcli.NewRunner(t, ctx, args...)
99-
stdout, stderr, err := c.Run()
100-
return stdout.String(), stderr.String(), err
101-
}
102-
103-
func deployBundleWithArgs(t testutil.TestingT, ctx context.Context, path string, args ...string) (string, string) {
104-
stdout, stderr, err := deployBundleWithArgsErr(t, ctx, path, args...)
105-
require.NoError(t, err)
106-
return stdout, stderr
107-
}
108-
10981
func runResource(t testutil.TestingT, ctx context.Context, path, key string) (string, error) {
11082
ctx = env.Set(ctx, "BUNDLE_ROOT", path)
11183
ctx = cmdio.NewContext(ctx, cmdio.Default())

0 commit comments

Comments
 (0)