From fab3e8f168c4fa8811991f407ff64232249f84d1 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Wed, 20 Nov 2024 13:20:39 +0100 Subject: [PATCH] Added integration test to deploy bundle to /Shared root path (#1914) ## Changes Added integration test to deploy bundle to /Shared root path ## Tests ``` --- PASS: TestAccDeployBasicToSharedWorkspace (24.58s) PASS coverage: 31.2% of statements in ./... ok github.com/databricks/cli/internal/bundle 25.572s coverage: 31.2% of statements in ./... ``` --------- Co-authored-by: shreyas-goenka <88374338+shreyas-goenka@users.noreply.github.com> --- .../basic/databricks_template_schema.json | 5 +++ .../basic/template/databricks.yml.tmpl | 4 ++ internal/bundle/deploy_to_shared_test.go | 38 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 internal/bundle/deploy_to_shared_test.go diff --git a/internal/bundle/bundles/basic/databricks_template_schema.json b/internal/bundle/bundles/basic/databricks_template_schema.json index c1c5cf12..41a723b0 100644 --- a/internal/bundle/bundles/basic/databricks_template_schema.json +++ b/internal/bundle/bundles/basic/databricks_template_schema.json @@ -11,6 +11,11 @@ "node_type_id": { "type": "string", "description": "Node type id for job cluster" + }, + "root_path": { + "type": "string", + "description": "Root path to deploy bundle to", + "default": "" } } } diff --git a/internal/bundle/bundles/basic/template/databricks.yml.tmpl b/internal/bundle/bundles/basic/template/databricks.yml.tmpl index a88cbd30..0eca4231 100644 --- a/internal/bundle/bundles/basic/template/databricks.yml.tmpl +++ b/internal/bundle/bundles/basic/template/databricks.yml.tmpl @@ -2,7 +2,11 @@ bundle: name: basic workspace: + {{ if .root_path }} + root_path: "{{.root_path}}/.bundle/{{.unique_id}}" + {{ else }} root_path: "~/.bundle/{{.unique_id}}" + {{ end }} resources: jobs: diff --git a/internal/bundle/deploy_to_shared_test.go b/internal/bundle/deploy_to_shared_test.go new file mode 100644 index 00000000..568c1fb5 --- /dev/null +++ b/internal/bundle/deploy_to_shared_test.go @@ -0,0 +1,38 @@ +package bundle + +import ( + "fmt" + "testing" + + "github.com/databricks/cli/internal" + "github.com/databricks/cli/internal/acc" + "github.com/databricks/cli/libs/env" + "github.com/google/uuid" + "github.com/stretchr/testify/require" +) + +func TestAccDeployBasicToSharedWorkspacePath(t *testing.T) { + ctx, wt := acc.WorkspaceTest(t) + + nodeTypeId := internal.GetNodeTypeId(env.Get(ctx, "CLOUD_ENV")) + uniqueId := uuid.New().String() + + currentUser, err := wt.W.CurrentUser.Me(ctx) + require.NoError(t, err) + + bundleRoot, err := initTestTemplate(t, ctx, "basic", map[string]any{ + "unique_id": uniqueId, + "node_type_id": nodeTypeId, + "spark_version": defaultSparkVersion, + "root_path": fmt.Sprintf("/Shared/%s", currentUser.UserName), + }) + require.NoError(t, err) + + t.Cleanup(func() { + err = destroyBundle(wt.T, ctx, bundleRoot) + require.NoError(wt.T, err) + }) + + err = deployBundle(wt.T, ctx, bundleRoot) + require.NoError(wt.T, err) +}