move tests

This commit is contained in:
Shreyas Goenka 2024-05-16 16:04:33 +02:00
parent 9e0291e1b7
commit 55dcd1dc3a
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
9 changed files with 46 additions and 23 deletions

View File

@ -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())

View File

@ -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{}

View File

@ -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)
})
}
}