Skip to content

Commit ed1a981

Browse files
authored
Convert TestBasicBundleDeployWithDoubleUnderscoreVariables integration test to an acceptance test (#2882)
## 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 11e1622 commit ed1a981

11 files changed

Lines changed: 66 additions & 93 deletions

File tree

integration/bundle/bundles/basic_with_variables/template/databricks.yml.tmpl renamed to acceptance/bundle/deploy/jobs/double-underscore-keys/databricks.yml.tmpl

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
bundle:
2-
name: basic
3-
4-
workspace:
5-
{{ if .root_path }}
6-
root_path: "{{.root_path}}/.bundle/{{.unique_id}}"
7-
{{ else }}
8-
root_path: "~/.bundle/{{.unique_id}}"
9-
{{ end }}
2+
name: deploy-jobs-test-$UNIQUE_NAME
103

114
variables:
125
task__key: # Note: the variable has double underscore
@@ -15,17 +8,17 @@ variables:
158
resources:
169
jobs:
1710
foo__bar: # Note: the resource has double underscore to check that TF provider can use such names
18-
name: test-job-basic-{{.unique_id}}
11+
name: test-job-basic-$UNIQUE_NAME
1912
tasks:
2013
- task_key: ${var.task__key}
2114
new_cluster:
2215
num_workers: 1
23-
spark_version: "{{.spark_version}}"
24-
node_type_id: "{{.node_type_id}}"
16+
spark_version: $DEFAULT_SPARK_VERSION
17+
node_type_id: $NODE_TYPE_ID
2518
spark_python_task:
2619
python_file: ./hello_world.py
2720
foo:
28-
name: test-job-basic-ref-{{.unique_id}}
21+
name: test-job-basic-ref-$UNIQUE_NAME
2922
tasks:
3023
- task_key: job_task
3124
run_job_task:

integration/bundle/bundles/basic_with_variables/template/hello_world.py renamed to acceptance/bundle/deploy/jobs/double-underscore-keys/hello_world.py

File renamed without changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
>>> [CLI] bundle validate
3+
Name: deploy-jobs-test-[UNIQUE_NAME]
4+
Target: default
5+
Workspace:
6+
User: [USERNAME]
7+
Path: /Workspace/Users/[USERNAME]/.bundle/deploy-jobs-test-[UNIQUE_NAME]/default
8+
9+
Validation OK!
10+
11+
>>> [CLI] bundle deploy
12+
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/deploy-jobs-test-[UNIQUE_NAME]/default/files...
13+
Deploying resources...
14+
Updating deployment state...
15+
Deployment complete!
16+
17+
>>> [CLI] bundle destroy --auto-approve
18+
The following resources will be deleted:
19+
delete job foo
20+
delete job foo__bar
21+
22+
All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/deploy-jobs-test-[UNIQUE_NAME]/default
23+
24+
Deleting files...
25+
Destroy complete!
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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 validate
9+
trace $CLI bundle deploy
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Local = true
2+
Cloud = true
3+
4+
Ignore = [
5+
"databricks.yml",
6+
]

acceptance/internal/handlers.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,17 @@ func addDefaultHandlers(server *testserver.Server) {
153153
return req.Workspace.JobsCreate(request)
154154
})
155155

156+
server.Handle("POST", "/api/2.2/jobs/delete", func(req testserver.Request) any {
157+
var request jobs.DeleteJob
158+
if err := json.Unmarshal(req.Body, &request); err != nil {
159+
return testserver.Response{
160+
Body: fmt.Sprintf("internal error: %s", err),
161+
StatusCode: 500,
162+
}
163+
}
164+
return testserver.MapDelete(req.Workspace, req.Workspace.Jobs, request.JobId)
165+
})
166+
156167
server.Handle("POST", "/api/2.2/jobs/reset", func(req testserver.Request) any {
157168
var request jobs.ResetJob
158169
if err := json.Unmarshal(req.Body, &request); err != nil {

integration/bundle/basic_test.go

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import (
66
"testing"
77

88
"github.com/databricks/cli/integration/internal/acc"
9-
"github.com/databricks/cli/internal/testcli"
109
"github.com/databricks/cli/internal/testutil"
11-
"github.com/databricks/cli/libs/testdiff"
1210
"github.com/google/uuid"
1311
"github.com/stretchr/testify/require"
1412
)
@@ -37,40 +35,3 @@ func TestBasicBundleDeployWithFailOnActiveRuns(t *testing.T) {
3735
// deploy empty bundle again
3836
deployBundleWithFlags(t, ctx, root, []string{"--fail-on-active-runs"})
3937
}
40-
41-
func TestBasicBundleDeployWithDoubleUnderscoreVariables(t *testing.T) {
42-
ctx, wt := acc.WorkspaceTest(t)
43-
44-
nodeTypeId := testutil.GetCloud(t).NodeTypeID()
45-
uniqueId := uuid.New().String()
46-
root := initTestTemplate(t, ctx, "basic_with_variables", map[string]any{
47-
"unique_id": uniqueId,
48-
"node_type_id": nodeTypeId,
49-
"spark_version": defaultSparkVersion,
50-
})
51-
52-
currentUser, err := wt.W.CurrentUser.Me(ctx)
53-
require.NoError(t, err)
54-
55-
ctx, replacements := testdiff.WithReplacementsMap(ctx)
56-
replacements.Set(uniqueId, "$UNIQUE_PRJ")
57-
replacements.Set(currentUser.UserName, "$USERNAME")
58-
59-
t.Cleanup(func() {
60-
destroyBundle(t, ctx, root)
61-
})
62-
63-
testutil.Chdir(t, root)
64-
testcli.AssertOutput(
65-
t,
66-
ctx,
67-
[]string{"bundle", "validate"},
68-
testutil.TestData("testdata/basic_with_variables/bundle_validate.txt"),
69-
)
70-
testcli.AssertOutput(
71-
t,
72-
ctx,
73-
[]string{"bundle", "deploy", "--force-lock", "--auto-approve"},
74-
testutil.TestData("testdata/basic_with_variables/bundle_deploy.txt"),
75-
)
76-
}

integration/bundle/bundles/basic_with_variables/databricks_template_schema.json

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

integration/bundle/testdata/basic_with_variables/bundle_deploy.txt

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

integration/bundle/testdata/basic_with_variables/bundle_validate.txt

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

0 commit comments

Comments
 (0)