From 55dcd1dc3ab31e22aaae0a379ed24a7e908445b6 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Thu, 16 May 2024 16:04:33 +0200 Subject: [PATCH] move tests --- bundle/config/root_test.go | 23 ---------- .../config/validate/unique_resource_keys.go | 1 + .../databricks.yml | 3 ++ .../resources.yml | 0 .../databricks.yml | 0 .../resources.yml | 0 .../databricks.yml | 0 .../databricks.yml | 0 bundle/tests/validate_test.go | 42 +++++++++++++++++++ 9 files changed, 46 insertions(+), 23 deletions(-) rename bundle/{config/testdata/duplicate_resource_name_in_subconfiguration_job_and_job => tests/validate/duplicate_resource_name_in_subconfiguration}/databricks.yml (76%) rename bundle/{config/testdata => tests/validate}/duplicate_resource_name_in_subconfiguration/resources.yml (100%) rename bundle/{config/testdata/duplicate_resource_name_in_subconfiguration => tests/validate/duplicate_resource_name_in_subconfiguration_job_and_job}/databricks.yml (100%) rename bundle/{config/testdata => tests/validate}/duplicate_resource_name_in_subconfiguration_job_and_job/resources.yml (100%) rename bundle/{config/testdata => tests/validate}/duplicate_resource_names_in_root_job_and_experiment/databricks.yml (100%) rename bundle/{config/testdata => tests/validate}/duplicate_resource_names_in_root_job_and_pipeline/databricks.yml (100%) create mode 100644 bundle/tests/validate_test.go diff --git a/bundle/config/root_test.go b/bundle/config/root_test.go index 4156b3384..bd044a697 100644 --- a/bundle/config/root_test.go +++ b/bundle/config/root_test.go @@ -30,29 +30,6 @@ func TestRootLoad(t *testing.T) { assert.Equal(t, "basic", root.Bundle.Name) } -func TestDuplicateIdOnLoadReturnsErrorForJobAndPipeline(t *testing.T) { - _, diags := Load("./testdata/duplicate_resource_names_in_root_job_and_pipeline/databricks.yml") - assert.NoError(t, diags.Error()) - - 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) { - _, diags := Load("./testdata/duplicate_resource_names_in_root_job_and_experiment/databricks.yml") - assert.ErrorContains(t, diags.Error(), "multiple resources named foo (job at ./testdata/duplicate_resource_names_in_root_job_and_experiment/databricks.yml:10:7, experiment at ./testdata/duplicate_resource_names_in_root_job_and_experiment/databricks.yml:18:7)") -} - -func TestDuplicateIdOnMergeReturnsErrorForJobAndPipeline(t *testing.T) { - root, diags := Load("./testdata/duplicate_resource_name_in_subconfiguration/databricks.yml") - require.NoError(t, diags.Error()) - - other, diags := Load("./testdata/duplicate_resource_name_in_subconfiguration/resources.yml") - require.NoError(t, diags.Error()) - - err := root.Merge(other) - assert.ErrorContains(t, err, "multiple resources named foo (job at ./testdata/duplicate_resource_name_in_subconfiguration/databricks.yml:10:7, pipeline at ./testdata/duplicate_resource_name_in_subconfiguration/resources.yml:4:7)") -} - func TestDuplicateIdOnMergeReturnsErrorForJobAndJob(t *testing.T) { root, diags := Load("./testdata/duplicate_resource_name_in_subconfiguration_job_and_job/databricks.yml") require.NoError(t, diags.Error()) diff --git a/bundle/config/validate/unique_resource_keys.go b/bundle/config/validate/unique_resource_keys.go index 86df0988c..fb270b15e 100644 --- a/bundle/config/validate/unique_resource_keys.go +++ b/bundle/config/validate/unique_resource_keys.go @@ -22,6 +22,7 @@ func (m *uniqueResourceKeys) Name() string { } // TODO: Ensure all duplicate key sites are returned to the user in the diagnostics. +// TODO: Add unit tests for this mutator. func (m *uniqueResourceKeys) Apply(ctx context.Context, rb bundle.ReadOnlyBundle) diag.Diagnostics { diags := diag.Diagnostics{} diff --git a/bundle/config/testdata/duplicate_resource_name_in_subconfiguration_job_and_job/databricks.yml b/bundle/tests/validate/duplicate_resource_name_in_subconfiguration/databricks.yml similarity index 76% rename from bundle/config/testdata/duplicate_resource_name_in_subconfiguration_job_and_job/databricks.yml rename to bundle/tests/validate/duplicate_resource_name_in_subconfiguration/databricks.yml index a81602920..5bec67483 100644 --- a/bundle/config/testdata/duplicate_resource_name_in_subconfiguration_job_and_job/databricks.yml +++ b/bundle/tests/validate/duplicate_resource_name_in_subconfiguration/databricks.yml @@ -4,6 +4,9 @@ bundle: workspace: profile: test +include: + - ./resources.yml + resources: jobs: foo: diff --git a/bundle/config/testdata/duplicate_resource_name_in_subconfiguration/resources.yml b/bundle/tests/validate/duplicate_resource_name_in_subconfiguration/resources.yml similarity index 100% rename from bundle/config/testdata/duplicate_resource_name_in_subconfiguration/resources.yml rename to bundle/tests/validate/duplicate_resource_name_in_subconfiguration/resources.yml diff --git a/bundle/config/testdata/duplicate_resource_name_in_subconfiguration/databricks.yml b/bundle/tests/validate/duplicate_resource_name_in_subconfiguration_job_and_job/databricks.yml similarity index 100% rename from bundle/config/testdata/duplicate_resource_name_in_subconfiguration/databricks.yml rename to bundle/tests/validate/duplicate_resource_name_in_subconfiguration_job_and_job/databricks.yml diff --git a/bundle/config/testdata/duplicate_resource_name_in_subconfiguration_job_and_job/resources.yml b/bundle/tests/validate/duplicate_resource_name_in_subconfiguration_job_and_job/resources.yml similarity index 100% rename from bundle/config/testdata/duplicate_resource_name_in_subconfiguration_job_and_job/resources.yml rename to bundle/tests/validate/duplicate_resource_name_in_subconfiguration_job_and_job/resources.yml diff --git a/bundle/config/testdata/duplicate_resource_names_in_root_job_and_experiment/databricks.yml b/bundle/tests/validate/duplicate_resource_names_in_root_job_and_experiment/databricks.yml similarity index 100% rename from bundle/config/testdata/duplicate_resource_names_in_root_job_and_experiment/databricks.yml rename to bundle/tests/validate/duplicate_resource_names_in_root_job_and_experiment/databricks.yml diff --git a/bundle/config/testdata/duplicate_resource_names_in_root_job_and_pipeline/databricks.yml b/bundle/tests/validate/duplicate_resource_names_in_root_job_and_pipeline/databricks.yml similarity index 100% rename from bundle/config/testdata/duplicate_resource_names_in_root_job_and_pipeline/databricks.yml rename to bundle/tests/validate/duplicate_resource_names_in_root_job_and_pipeline/databricks.yml diff --git a/bundle/tests/validate_test.go b/bundle/tests/validate_test.go new file mode 100644 index 000000000..e96544bfe --- /dev/null +++ b/bundle/tests/validate_test.go @@ -0,0 +1,42 @@ +package config_tests + +import ( + "context" + "testing" + + "github.com/databricks/cli/bundle" + "github.com/databricks/cli/bundle/config/validate" + "github.com/stretchr/testify/assert" +) + +func TestValidateUniqueResourceIdentifiers(t *testing.T) { + tcases := []struct { + name string + errorMsg string + }{ + { + name: "duplicate_resource_names_in_root_job_and_pipeline", + errorMsg: "multiple resources named foo (jobs.foo at validate/duplicate_resource_names_in_root_job_and_pipeline/databricks.yml:10:7, pipelines.foo at validate/duplicate_resource_names_in_root_job_and_pipeline/databricks.yml:13:7)", + }, + { + name: "duplicate_resource_names_in_root_job_and_experiment", + errorMsg: "multiple resources named foo (jobs.foo at validate/duplicate_resource_names_in_root_job_and_experiment/databricks.yml:10:7, experiments.foo at validate/duplicate_resource_names_in_root_job_and_experiment/databricks.yml:18:7)", + }, + { + name: "duplicate_resource_name_in_subconfiguration", + errorMsg: "multiple resources named foo (jobs.foo at validate/duplicate_resource_name_in_subconfiguration/databricks.yml:13:7, pipelines.foo at validate/duplicate_resource_name_in_subconfiguration/resources.yml:4:7)", + }, + // { + // name: "duplicate_resource_name_in_subconfiguration_job_and_job", + // errorMsg: "multiple resources named foo (jobs.foo at validate/duplicate_resource_name_in_subconfiguration_job_and_job/databricks.yml:10:7, jobs.foo at validate/duplicate_resource_name_in_subconfiguration_job_and_job/resources.yml:4:7)", + // }, + } + + for _, tc := range tcases { + t.Run(tc.name, func(t *testing.T) { + b := load(t, "./validate/"+tc.name) + diags := bundle.ApplyReadOnly(context.Background(), bundle.ReadOnly(b), validate.UniqueResourceKeys()) + assert.ErrorContains(t, diags.Error(), tc.errorMsg) + }) + } +}