From 27a1c7cbe4709ef0a4bb822becc3ac8228af78c4 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Thu, 2 May 2024 16:33:48 +0200 Subject: [PATCH] added and fixed tests --- bundle/config/root_test.go | 21 +++++++++++++++++- .../databricks.yml | 4 ---- .../databricks.yml | 22 +++++++++++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 bundle/config/testdata/gather_resource_identifiers/databricks.yml diff --git a/bundle/config/root_test.go b/bundle/config/root_test.go index f64a2a3b..71440e95 100644 --- a/bundle/config/root_test.go +++ b/bundle/config/root_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/databricks/cli/bundle/config/variable" + "github.com/databricks/cli/libs/dyn" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -32,7 +33,7 @@ func TestRootLoad(t *testing.T) { func TestDuplicateIdOnLoadReturnsErrorForJobAndPipeline(t *testing.T) { _, diags := Load("./testdata/duplicate_resource_names_in_root_job_and_pipeline/databricks.yml") - assert.ErrorContains(t, diags.Error(), "multiple resources named foo (job at ./testdata/duplicate_resource_names_in_root_job_and_pipeline/databricks.yml:10:7, pipeline at ./testdata/duplicate_resource_names_in_root_job_and_pipeline/databricks.yml:15:7)") + assert.ErrorContains(t, diags.Error(), "multiple resources named foo (job at ./testdata/duplicate_resource_names_in_root_job_and_pipeline/databricks.yml:10:7, pipeline at ./testdata/duplicate_resource_names_in_root_job_and_pipeline/databricks.yml:13:7)") } func TestDuplicateIdOnLoadReturnsErrorForJobsAndExperiments(t *testing.T) { @@ -62,6 +63,24 @@ func TestDuplicateIdOnMergeReturnsErrorForJobAndJob(t *testing.T) { assert.ErrorContains(t, err, "multiple resources named foo (job at ./testdata/duplicate_resource_name_in_subconfiguration_job_and_job/databricks.yml:10:7, job at ./testdata/duplicate_resource_name_in_subconfiguration_job_and_job/resources.yml:4:7)") } +func TestGatherResourceIdentifiers(t *testing.T) { + root, diags := Load("./testdata/gather_resource_identifiers/databricks.yml") + require.NoError(t, diags.Error()) + + actual, err := root.gatherResourceIdentifiers() + assert.NoError(t, err) + + expected := map[string]dyn.Path{ + "foo": dyn.MustPathFromString("jobs.foo"), + "bar": dyn.MustPathFromString("jobs.bar"), + "zab": dyn.MustPathFromString("pipelines.zab"), + "baz": dyn.MustPathFromString("pipelines.baz"), + "zaz": dyn.MustPathFromString("experiments.zaz"), + "zuz": dyn.MustPathFromString("experiments.zuz"), + } + assert.Equal(t, expected, actual) +} + func TestInitializeVariables(t *testing.T) { fooDefault := "abc" root := &Root{ diff --git a/bundle/config/testdata/duplicate_resource_names_in_root_job_and_pipeline/databricks.yml b/bundle/config/testdata/duplicate_resource_names_in_root_job_and_pipeline/databricks.yml index 9189fe4e..1e9aa10b 100644 --- a/bundle/config/testdata/duplicate_resource_names_in_root_job_and_pipeline/databricks.yml +++ b/bundle/config/testdata/duplicate_resource_names_in_root_job_and_pipeline/databricks.yml @@ -8,10 +8,6 @@ resources: jobs: foo: name: job foo - bar: - name: job bar pipelines: foo: name: pipeline foo - baz: - name: pipeline baz diff --git a/bundle/config/testdata/gather_resource_identifiers/databricks.yml b/bundle/config/testdata/gather_resource_identifiers/databricks.yml new file mode 100644 index 00000000..4291e222 --- /dev/null +++ b/bundle/config/testdata/gather_resource_identifiers/databricks.yml @@ -0,0 +1,22 @@ +bundle: + name: test + +workspace: + profile: test + +resources: + jobs: + foo: + name: job foo + bar: + name: job bar + pipelines: + zab: + name: pipeline foo + baz: + name: pipeline baz + experiments: + zaz: + name: experiment zaz + zuz: + name: experiment zuz