From dc54281690f11df72672b838ada7d3f922ad6029 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Wed, 16 Apr 2025 15:38:26 +0200 Subject: [PATCH 1/5] Convert dashboard defaults test to acceptance --- .../dashboard_defaults/databricks.yml | 22 +++ .../validate/dashboard_defaults/output.txt | 23 +++ .../bundle/validate/dashboard_defaults/script | 1 + .../configure_dashboard_defaults_test.go | 131 ------------------ 4 files changed, 46 insertions(+), 131 deletions(-) create mode 100644 acceptance/bundle/validate/dashboard_defaults/databricks.yml create mode 100644 acceptance/bundle/validate/dashboard_defaults/output.txt create mode 100644 acceptance/bundle/validate/dashboard_defaults/script delete mode 100644 bundle/config/mutator/resourcemutator/configure_dashboard_defaults_test.go diff --git a/acceptance/bundle/validate/dashboard_defaults/databricks.yml b/acceptance/bundle/validate/dashboard_defaults/databricks.yml new file mode 100644 index 0000000000..beb428e17f --- /dev/null +++ b/acceptance/bundle/validate/dashboard_defaults/databricks.yml @@ -0,0 +1,22 @@ +bundle: + name: BUNDLE + +workspace: + resource_path: /foo/bar + +resources: + dashboards: + d1: + # unchanged + parent_path: "" + + d2: + # unchanged + parent_path: "already-set" + + d3: + display_name: hello + # parent_path set default + + d4: + embed_credentials: true diff --git a/acceptance/bundle/validate/dashboard_defaults/output.txt b/acceptance/bundle/validate/dashboard_defaults/output.txt new file mode 100644 index 0000000000..dc4eae47ba --- /dev/null +++ b/acceptance/bundle/validate/dashboard_defaults/output.txt @@ -0,0 +1,23 @@ +{ + "d1": { + "embed_credentials": false, + "parent_path": "", + "permissions": [] + }, + "d2": { + "embed_credentials": false, + "parent_path": "already-set", + "permissions": [] + }, + "d3": { + "display_name": "hello", + "embed_credentials": false, + "parent_path": "/Workspace/foo/bar", + "permissions": [] + }, + "d4": { + "embed_credentials": true, + "parent_path": "/Workspace/foo/bar", + "permissions": [] + } +} diff --git a/acceptance/bundle/validate/dashboard_defaults/script b/acceptance/bundle/validate/dashboard_defaults/script new file mode 100644 index 0000000000..b3971c0778 --- /dev/null +++ b/acceptance/bundle/validate/dashboard_defaults/script @@ -0,0 +1 @@ +$CLI bundle validate -o json | jq .resources.dashboards diff --git a/bundle/config/mutator/resourcemutator/configure_dashboard_defaults_test.go b/bundle/config/mutator/resourcemutator/configure_dashboard_defaults_test.go deleted file mode 100644 index c9d6913d84..0000000000 --- a/bundle/config/mutator/resourcemutator/configure_dashboard_defaults_test.go +++ /dev/null @@ -1,131 +0,0 @@ -package resourcemutator_test - -import ( - "context" - "testing" - - "github.com/databricks/cli/bundle/config/mutator/resourcemutator" - - "github.com/databricks/cli/bundle" - "github.com/databricks/cli/bundle/config" - "github.com/databricks/cli/bundle/config/resources" - "github.com/databricks/cli/bundle/internal/bundletest" - "github.com/databricks/cli/libs/dyn" - "github.com/databricks/databricks-sdk-go/service/dashboards" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestConfigureDashboardDefaultsParentPath(t *testing.T) { - b := &bundle.Bundle{ - Config: config.Root{ - Workspace: config.Workspace{ - ResourcePath: "/foo/bar", - }, - Resources: config.Resources{ - Dashboards: map[string]*resources.Dashboard{ - "d1": { - // Empty string is skipped. - // See below for how it is set. - Dashboard: &dashboards.Dashboard{ - ParentPath: "", - }, - }, - "d2": { - // Non-empty string is skipped. - Dashboard: &dashboards.Dashboard{ - ParentPath: "already-set", - }, - }, - "d3": { - // No parent path set. - }, - "d4": nil, - }, - }, - }, - } - - // We can't set an empty string in the typed configuration. - // Do it on the dyn.Value directly. - bundletest.Mutate(t, b, func(v dyn.Value) (dyn.Value, error) { - return dyn.Set(v, "resources.dashboards.d1.parent_path", dyn.V("")) - }) - - diags := bundle.Apply(context.Background(), b, resourcemutator.ConfigureDashboardDefaults()) - require.NoError(t, diags.Error()) - - var v dyn.Value - var err error - - // Set to empty string; unchanged. - v, err = dyn.Get(b.Config.Value(), "resources.dashboards.d1.parent_path") - if assert.NoError(t, err) { - assert.Equal(t, "", v.MustString()) - } - - // Set to "already-set"; unchanged. - v, err = dyn.Get(b.Config.Value(), "resources.dashboards.d2.parent_path") - if assert.NoError(t, err) { - assert.Equal(t, "already-set", v.MustString()) - } - - // Not set; now set to the workspace resource path. - v, err = dyn.Get(b.Config.Value(), "resources.dashboards.d3.parent_path") - if assert.NoError(t, err) { - assert.Equal(t, "/foo/bar", v.MustString()) - } - - // No valid dashboard; no change. - _, err = dyn.Get(b.Config.Value(), "resources.dashboards.d4.parent_path") - assert.True(t, dyn.IsCannotTraverseNilError(err)) -} - -func TestConfigureDashboardDefaultsEmbedCredentials(t *testing.T) { - b := &bundle.Bundle{ - Config: config.Root{ - Resources: config.Resources{ - Dashboards: map[string]*resources.Dashboard{ - "d1": { - EmbedCredentials: true, - }, - "d2": { - EmbedCredentials: false, - }, - "d3": { - // No parent path set. - }, - "d4": nil, - }, - }, - }, - } - - diags := bundle.Apply(context.Background(), b, resourcemutator.ConfigureDashboardDefaults()) - require.NoError(t, diags.Error()) - - var v dyn.Value - var err error - - // Set to true; still true. - v, err = dyn.Get(b.Config.Value(), "resources.dashboards.d1.embed_credentials") - if assert.NoError(t, err) { - assert.True(t, v.MustBool()) - } - - // Set to false; still false. - v, err = dyn.Get(b.Config.Value(), "resources.dashboards.d2.embed_credentials") - if assert.NoError(t, err) { - assert.False(t, v.MustBool()) - } - - // Not set; now false. - v, err = dyn.Get(b.Config.Value(), "resources.dashboards.d3.embed_credentials") - if assert.NoError(t, err) { - assert.False(t, v.MustBool()) - } - - // No valid dashboard; no change. - _, err = dyn.Get(b.Config.Value(), "resources.dashboards.d4.embed_credentials") - assert.True(t, dyn.IsCannotTraverseNilError(err)) -} From 70a394a427e412d4f12049f0c442cf3785fe7696 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Wed, 16 Apr 2025 15:44:36 +0200 Subject: [PATCH 2/5] add volumes --- .../bundle/validate/volume_defaults/databricks.yml | 13 +++++++++++++ .../bundle/validate/volume_defaults/output.txt | 12 ++++++++++++ acceptance/bundle/validate/volume_defaults/script | 1 + 3 files changed, 26 insertions(+) create mode 100644 acceptance/bundle/validate/volume_defaults/databricks.yml create mode 100644 acceptance/bundle/validate/volume_defaults/output.txt create mode 100644 acceptance/bundle/validate/volume_defaults/script diff --git a/acceptance/bundle/validate/volume_defaults/databricks.yml b/acceptance/bundle/validate/volume_defaults/databricks.yml new file mode 100644 index 0000000000..ed05e939d7 --- /dev/null +++ b/acceptance/bundle/validate/volume_defaults/databricks.yml @@ -0,0 +1,13 @@ +bundle: + name: BUNDLE + +resources: + volumes: + v1: + volume_type: "" + + v2: + volume_type: "already-set" + + v3: + comment: hello diff --git a/acceptance/bundle/validate/volume_defaults/output.txt b/acceptance/bundle/validate/volume_defaults/output.txt new file mode 100644 index 0000000000..f128a32958 --- /dev/null +++ b/acceptance/bundle/validate/volume_defaults/output.txt @@ -0,0 +1,12 @@ +{ + "v1": { + "volume_type": "" + }, + "v2": { + "volume_type": "already-set" + }, + "v3": { + "comment": "hello", + "volume_type": "MANAGED" + } +} diff --git a/acceptance/bundle/validate/volume_defaults/script b/acceptance/bundle/validate/volume_defaults/script new file mode 100644 index 0000000000..d99405ad92 --- /dev/null +++ b/acceptance/bundle/validate/volume_defaults/script @@ -0,0 +1 @@ +$CLI bundle validate -o json | jq .resources.volumes From 7b0a0a6b49313a7eedd3de1a7449ce9e91c0b0da Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Wed, 16 Apr 2025 15:44:59 +0200 Subject: [PATCH 3/5] rm old test --- .../configure_volume_defaults_test.go | 76 ------------------- 1 file changed, 76 deletions(-) delete mode 100644 bundle/config/mutator/resourcemutator/configure_volume_defaults_test.go diff --git a/bundle/config/mutator/resourcemutator/configure_volume_defaults_test.go b/bundle/config/mutator/resourcemutator/configure_volume_defaults_test.go deleted file mode 100644 index 4c873b253b..0000000000 --- a/bundle/config/mutator/resourcemutator/configure_volume_defaults_test.go +++ /dev/null @@ -1,76 +0,0 @@ -package resourcemutator_test - -import ( - "context" - "testing" - - "github.com/databricks/cli/bundle/config/mutator/resourcemutator" - - "github.com/databricks/cli/bundle" - "github.com/databricks/cli/bundle/config" - "github.com/databricks/cli/bundle/config/resources" - "github.com/databricks/cli/bundle/internal/bundletest" - "github.com/databricks/cli/libs/dyn" - "github.com/databricks/databricks-sdk-go/service/catalog" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestConfigureVolumeDefaultsVolumeType(t *testing.T) { - b := &bundle.Bundle{ - Config: config.Root{ - Resources: config.Resources{ - Volumes: map[string]*resources.Volume{ - "v1": { - // Empty string is skipped. - // See below for how it is set. - CreateVolumeRequestContent: &catalog.CreateVolumeRequestContent{ - VolumeType: "", - }, - }, - "v2": { - // Non-empty string is skipped. - CreateVolumeRequestContent: &catalog.CreateVolumeRequestContent{ - VolumeType: "already-set", - }, - }, - "v3": { - // No volume type set. - }, - "v4": nil, - }, - }, - }, - } - - // We can't set an empty string in the typed configuration. - // Do it on the dyn.Value directly. - bundletest.Mutate(t, b, func(v dyn.Value) (dyn.Value, error) { - return dyn.Set(v, "resources.volumes.v1.volume_type", dyn.V("")) - }) - - diags := bundle.Apply(context.Background(), b, resourcemutator.ConfigureVolumeDefaults()) - require.NoError(t, diags.Error()) - - var v dyn.Value - var err error - - // Set to empty string; unchanged. - v, err = dyn.Get(b.Config.Value(), "resources.volumes.v1.volume_type") - require.NoError(t, err) - assert.Equal(t, "", v.MustString()) - - // Set to non-empty string; unchanged. - v, err = dyn.Get(b.Config.Value(), "resources.volumes.v2.volume_type") - require.NoError(t, err) - assert.Equal(t, "already-set", v.MustString()) - - // Not set; set to default. - v, err = dyn.Get(b.Config.Value(), "resources.volumes.v3.volume_type") - require.NoError(t, err) - assert.Equal(t, "MANAGED", v.MustString()) - - // No valid volume; No change. - _, err = dyn.Get(b.Config.Value(), "resources.volumes.v4.volume_type") - assert.True(t, dyn.IsCannotTraverseNilError(err)) -} From 7a790a32259bd72930d9c8af96fb2fe17d4fceeb Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Wed, 16 Apr 2025 15:54:23 +0200 Subject: [PATCH 4/5] ws fix --- acceptance/bundle/validate/volume_defaults/databricks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acceptance/bundle/validate/volume_defaults/databricks.yml b/acceptance/bundle/validate/volume_defaults/databricks.yml index ed05e939d7..d0fa670ab1 100644 --- a/acceptance/bundle/validate/volume_defaults/databricks.yml +++ b/acceptance/bundle/validate/volume_defaults/databricks.yml @@ -10,4 +10,4 @@ resources: volume_type: "already-set" v3: - comment: hello + comment: hello From 41bf3472bc761c8532246e2b07142aa622d3fa2a Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Wed, 16 Apr 2025 15:58:33 +0200 Subject: [PATCH 5/5] add {} test case and give test cases descriptive names --- .../validate/dashboard_defaults/databricks.yml | 10 ++++++---- .../bundle/validate/dashboard_defaults/output.txt | 13 +++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/acceptance/bundle/validate/dashboard_defaults/databricks.yml b/acceptance/bundle/validate/dashboard_defaults/databricks.yml index beb428e17f..a8179e4661 100644 --- a/acceptance/bundle/validate/dashboard_defaults/databricks.yml +++ b/acceptance/bundle/validate/dashboard_defaults/databricks.yml @@ -6,17 +6,19 @@ workspace: resources: dashboards: - d1: + empty_string: # unchanged parent_path: "" - d2: + non_empty_string: # unchanged parent_path: "already-set" - d3: + other_fields: display_name: hello # parent_path set default - d4: + set_to_true: embed_credentials: true + + completely_empty: {} diff --git a/acceptance/bundle/validate/dashboard_defaults/output.txt b/acceptance/bundle/validate/dashboard_defaults/output.txt index dc4eae47ba..4de28d463c 100644 --- a/acceptance/bundle/validate/dashboard_defaults/output.txt +++ b/acceptance/bundle/validate/dashboard_defaults/output.txt @@ -1,21 +1,26 @@ { - "d1": { + "completely_empty": { + "embed_credentials": false, + "parent_path": "/Workspace/foo/bar", + "permissions": [] + }, + "empty_string": { "embed_credentials": false, "parent_path": "", "permissions": [] }, - "d2": { + "non_empty_string": { "embed_credentials": false, "parent_path": "already-set", "permissions": [] }, - "d3": { + "other_fields": { "display_name": "hello", "embed_credentials": false, "parent_path": "/Workspace/foo/bar", "permissions": [] }, - "d4": { + "set_to_true": { "embed_credentials": true, "parent_path": "/Workspace/foo/bar", "permissions": []