added and fixed tests

This commit is contained in:
Shreyas Goenka 2024-05-02 16:33:48 +02:00
parent be92aa639c
commit 27a1c7cbe4
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
3 changed files with 42 additions and 5 deletions

View File

@ -6,6 +6,7 @@ import (
"testing" "testing"
"github.com/databricks/cli/bundle/config/variable" "github.com/databricks/cli/bundle/config/variable"
"github.com/databricks/cli/libs/dyn"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -32,7 +33,7 @@ func TestRootLoad(t *testing.T) {
func TestDuplicateIdOnLoadReturnsErrorForJobAndPipeline(t *testing.T) { func TestDuplicateIdOnLoadReturnsErrorForJobAndPipeline(t *testing.T) {
_, diags := Load("./testdata/duplicate_resource_names_in_root_job_and_pipeline/databricks.yml") _, 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) { 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)") 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) { func TestInitializeVariables(t *testing.T) {
fooDefault := "abc" fooDefault := "abc"
root := &Root{ root := &Root{

View File

@ -8,10 +8,6 @@ resources:
jobs: jobs:
foo: foo:
name: job foo name: job foo
bar:
name: job bar
pipelines: pipelines:
foo: foo:
name: pipeline foo name: pipeline foo
baz:
name: pipeline baz

View File

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