databricks-cli/bundle/config/mutator/capture_schema_dependency_t...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

75 lines
2.0 KiB
Go
Raw Normal View History

2024-12-27 13:32:08 +00:00
package mutator
import (
"context"
"testing"
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/config/resources"
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/databricks/databricks-sdk-go/service/pipelines"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
2025-01-20 15:35:21 +00:00
func TestCaptureSchemaDependencyForVolumeWithEmptySchemas(t *testing.T) {
2024-12-27 13:32:08 +00:00
b := &bundle.Bundle{
Config: config.Root{
Resources: config.Resources{
Schemas: map[string]*resources.Schema{
2025-01-16 12:02:21 +00:00
"nilschema": nil,
"emptyschema": {},
2024-12-27 13:32:08 +00:00
},
Volumes: map[string]*resources.Volume{
"volume1": {
CreateVolumeRequestContent: &catalog.CreateVolumeRequestContent{
CatalogName: "catalog1",
SchemaName: "foobar",
},
},
2025-01-16 12:02:21 +00:00
"nilVolume": nil,
"emptyVolume": {},
2024-12-27 13:32:08 +00:00
},
},
},
}
2025-01-07 10:05:46 +00:00
d := bundle.Apply(context.Background(), b, CaptureSchemaDependency())
2024-12-27 13:32:08 +00:00
require.Nil(t, d)
2025-01-07 10:18:51 +00:00
2025-01-20 15:35:21 +00:00
assert.Equal(t, "foobar", b.Config.Resources.Volumes["volume1"].CreateVolumeRequestContent.SchemaName)
2025-01-16 12:02:21 +00:00
assert.Nil(t, b.Config.Resources.Volumes["nilVolume"])
assert.Nil(t, b.Config.Resources.Volumes["emptyVolume"].CreateVolumeRequestContent)
2024-12-27 13:32:08 +00:00
}
2025-01-20 15:35:21 +00:00
func TestCaptureSchemaDependencyForPipelinesWithEmptySchemas(t *testing.T) {
2024-12-27 13:32:08 +00:00
b := &bundle.Bundle{
Config: config.Root{
Resources: config.Resources{
Schemas: map[string]*resources.Schema{
2025-01-16 12:02:21 +00:00
"nilschema": nil,
"emptyschema": {},
2024-12-27 13:32:08 +00:00
},
Pipelines: map[string]*resources.Pipeline{
"pipeline1": {
PipelineSpec: &pipelines.PipelineSpec{
Catalog: "catalog1",
Schema: "foobar",
},
},
2025-01-16 12:02:21 +00:00
"nilPipeline": nil,
"emptyPipeline": {},
2024-12-27 13:32:08 +00:00
},
},
},
}
2025-01-07 10:05:46 +00:00
d := bundle.Apply(context.Background(), b, CaptureSchemaDependency())
2024-12-27 13:32:08 +00:00
require.Nil(t, d)
2025-01-07 10:18:51 +00:00
2025-01-20 15:35:21 +00:00
assert.Equal(t, "foobar", b.Config.Resources.Pipelines["pipeline1"].Schema)
2025-01-16 12:02:21 +00:00
assert.Nil(t, b.Config.Resources.Pipelines["nilPipeline"])
assert.Nil(t, b.Config.Resources.Pipelines["emptyPipeline"].PipelineSpec)
2024-12-27 13:32:08 +00:00
}