mirror of https://github.com/databricks/cli.git
move tests
This commit is contained in:
parent
9e0291e1b7
commit
55dcd1dc3a
|
@ -30,29 +30,6 @@ func TestRootLoad(t *testing.T) {
|
||||||
assert.Equal(t, "basic", root.Bundle.Name)
|
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) {
|
func TestDuplicateIdOnMergeReturnsErrorForJobAndJob(t *testing.T) {
|
||||||
root, diags := Load("./testdata/duplicate_resource_name_in_subconfiguration_job_and_job/databricks.yml")
|
root, diags := Load("./testdata/duplicate_resource_name_in_subconfiguration_job_and_job/databricks.yml")
|
||||||
require.NoError(t, diags.Error())
|
require.NoError(t, diags.Error())
|
||||||
|
|
|
@ -22,6 +22,7 @@ func (m *uniqueResourceKeys) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Ensure all duplicate key sites are returned to the user in the diagnostics.
|
// 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 {
|
func (m *uniqueResourceKeys) Apply(ctx context.Context, rb bundle.ReadOnlyBundle) diag.Diagnostics {
|
||||||
diags := diag.Diagnostics{}
|
diags := diag.Diagnostics{}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,9 @@ bundle:
|
||||||
workspace:
|
workspace:
|
||||||
profile: test
|
profile: test
|
||||||
|
|
||||||
|
include:
|
||||||
|
- ./resources.yml
|
||||||
|
|
||||||
resources:
|
resources:
|
||||||
jobs:
|
jobs:
|
||||||
foo:
|
foo:
|
|
@ -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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue