From fcc47de4fe4a6ba90c265be0d25cd5bf2482dabb Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Tue, 7 Jan 2025 15:48:51 +0530 Subject: [PATCH] address comments --- .../mutator/capture_schema_dependency.go | 6 ++ .../mutator/capture_schema_dependency_test.go | 62 +++++++++++++------ 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/bundle/config/mutator/capture_schema_dependency.go b/bundle/config/mutator/capture_schema_dependency.go index 1bbc4e6de..4cc59143d 100644 --- a/bundle/config/mutator/capture_schema_dependency.go +++ b/bundle/config/mutator/capture_schema_dependency.go @@ -40,6 +40,9 @@ func findSchema(b *bundle.Bundle, catalogName, schemaName string) (string, *reso } func resolveVolume(v *resources.Volume, b *bundle.Bundle) { + if v.CreateVolumeRequestContent == nil { + return + } schemaK, schema := findSchema(b, v.CatalogName, v.SchemaName) if schema == nil { return @@ -49,6 +52,9 @@ func resolveVolume(v *resources.Volume, b *bundle.Bundle) { } func resolvePipeline(p *resources.Pipeline, b *bundle.Bundle) { + if p.PipelineSpec == nil { + return + } // schema and target have the same semantics in the DLT API but are mutually // exclusive. If schema is set, the pipeline is in direct publishing mode // and can write tables to multiple schemas (vs target which is limited to a single schema). diff --git a/bundle/config/mutator/capture_schema_dependency_test.go b/bundle/config/mutator/capture_schema_dependency_test.go index 335783c91..b26b1eaca 100644 --- a/bundle/config/mutator/capture_schema_dependency_test.go +++ b/bundle/config/mutator/capture_schema_dependency_test.go @@ -72,6 +72,10 @@ func TestCaptureSchemaDependencyForVolume(t *testing.T) { SchemaName: "schemaX", }, }, + "nilVolume": {}, + "emptyVolume": { + CreateVolumeRequestContent: &catalog.CreateVolumeRequestContent{}, + }, }, }, }, @@ -79,11 +83,15 @@ func TestCaptureSchemaDependencyForVolume(t *testing.T) { d := bundle.Apply(context.Background(), b, CaptureSchemaDependency()) require.Nil(t, d) - assert.Equal(t, b.Config.Resources.Volumes["volume1"].CreateVolumeRequestContent.SchemaName, "${resources.schemas.schema1.name}") - assert.Equal(t, b.Config.Resources.Volumes["volume2"].CreateVolumeRequestContent.SchemaName, "${resources.schemas.schema2.name}") - assert.Equal(t, b.Config.Resources.Volumes["volume3"].CreateVolumeRequestContent.SchemaName, "${resources.schemas.schema3.name}") - assert.Equal(t, b.Config.Resources.Volumes["volume4"].CreateVolumeRequestContent.SchemaName, "foobar") - assert.Equal(t, b.Config.Resources.Volumes["volume5"].CreateVolumeRequestContent.SchemaName, "schemaX") + + assert.Equal(t, "${resources.schemas.schema1.name}", b.Config.Resources.Volumes["volume1"].CreateVolumeRequestContent.SchemaName) + assert.Equal(t, "${resources.schemas.schema2.name}", b.Config.Resources.Volumes["volume2"].CreateVolumeRequestContent.SchemaName) + assert.Equal(t, "${resources.schemas.schema3.name}", b.Config.Resources.Volumes["volume3"].CreateVolumeRequestContent.SchemaName) + assert.Equal(t, "foobar", b.Config.Resources.Volumes["volume4"].CreateVolumeRequestContent.SchemaName) + assert.Equal(t, "schemaX", b.Config.Resources.Volumes["volume5"].CreateVolumeRequestContent.SchemaName) + + assert.Nil(t, b.Config.Resources.Volumes["nilVolume"].CreateVolumeRequestContent) + assert.Empty(t, b.Config.Resources.Volumes["emptyVolume"].CreateVolumeRequestContent) } func TestCaptureSchemaDependencyForPipelinesWithTarget(t *testing.T) { @@ -109,6 +117,10 @@ func TestCaptureSchemaDependencyForPipelinesWithTarget(t *testing.T) { Name: "barfoo", }, }, + "nilschema": {}, + "emptyschema": { + CreateSchema: &catalog.CreateSchema{}, + }, }, Pipelines: map[string]*resources.Pipeline{ "pipeline1": { @@ -154,6 +166,10 @@ func TestCaptureSchemaDependencyForPipelinesWithTarget(t *testing.T) { Name: "whatever", }, }, + "nilPipeline": {}, + "emptyPipeline": { + PipelineSpec: &pipelines.PipelineSpec{}, + }, }, }, }, @@ -161,13 +177,17 @@ func TestCaptureSchemaDependencyForPipelinesWithTarget(t *testing.T) { d := bundle.Apply(context.Background(), b, CaptureSchemaDependency()) require.Nil(t, d) - assert.Equal(t, b.Config.Resources.Pipelines["pipeline1"].Schema, "${resources.schemas.schema1.name}") - assert.Equal(t, b.Config.Resources.Pipelines["pipeline2"].Schema, "${resources.schemas.schema2.name}") - assert.Equal(t, b.Config.Resources.Pipelines["pipeline3"].Schema, "${resources.schemas.schema3.name}") - assert.Equal(t, b.Config.Resources.Pipelines["pipeline4"].Schema, "foobar") - assert.Equal(t, b.Config.Resources.Pipelines["pipeline5"].Schema, "schemaX") - assert.Equal(t, b.Config.Resources.Pipelines["pipeline6"].Schema, "foobar") - assert.Equal(t, b.Config.Resources.Pipelines["pipeline7"].Schema, "") + + assert.Equal(t, "${resources.schemas.schema1.name}", b.Config.Resources.Pipelines["pipeline1"].Schema) + assert.Equal(t, "${resources.schemas.schema2.name}", b.Config.Resources.Pipelines["pipeline2"].Schema) + assert.Equal(t, "${resources.schemas.schema3.name}", b.Config.Resources.Pipelines["pipeline3"].Schema) + assert.Equal(t, "foobar", b.Config.Resources.Pipelines["pipeline4"].Schema) + assert.Equal(t, "schemaX", b.Config.Resources.Pipelines["pipeline5"].Schema) + assert.Equal(t, "foobar", b.Config.Resources.Pipelines["pipeline6"].Schema) + assert.Equal(t, "", b.Config.Resources.Pipelines["pipeline7"].Schema) + + assert.Nil(t, b.Config.Resources.Pipelines["nilPipeline"].PipelineSpec) + assert.Empty(t, b.Config.Resources.Pipelines["emptyPipeline"].PipelineSpec) for _, k := range []string{"pipeline1", "pipeline2", "pipeline3", "pipeline4", "pipeline5", "pipeline6", "pipeline7"} { assert.Empty(t, b.Config.Resources.Pipelines[k].Target) @@ -197,6 +217,10 @@ func TestCaptureSchemaDependencyForPipelinesWithSchema(t *testing.T) { Name: "barfoo", }, }, + "nilschema": {}, + "emptyschema": { + CreateSchema: &catalog.CreateSchema{}, + }, }, Pipelines: map[string]*resources.Pipeline{ "pipeline1": { @@ -249,13 +273,13 @@ func TestCaptureSchemaDependencyForPipelinesWithSchema(t *testing.T) { d := bundle.Apply(context.Background(), b, CaptureSchemaDependency()) require.Nil(t, d) - assert.Equal(t, b.Config.Resources.Pipelines["pipeline1"].Target, "${resources.schemas.schema1.name}") - assert.Equal(t, b.Config.Resources.Pipelines["pipeline2"].Target, "${resources.schemas.schema2.name}") - assert.Equal(t, b.Config.Resources.Pipelines["pipeline3"].Target, "${resources.schemas.schema3.name}") - assert.Equal(t, b.Config.Resources.Pipelines["pipeline4"].Target, "foobar") - assert.Equal(t, b.Config.Resources.Pipelines["pipeline5"].Target, "schemaX") - assert.Equal(t, b.Config.Resources.Pipelines["pipeline6"].Target, "foobar") - assert.Equal(t, b.Config.Resources.Pipelines["pipeline7"].Target, "") + assert.Equal(t, "${resources.schemas.schema1.name}", b.Config.Resources.Pipelines["pipeline1"].Target) + assert.Equal(t, "${resources.schemas.schema2.name}", b.Config.Resources.Pipelines["pipeline2"].Target) + assert.Equal(t, "${resources.schemas.schema3.name}", b.Config.Resources.Pipelines["pipeline3"].Target) + assert.Equal(t, "foobar", b.Config.Resources.Pipelines["pipeline4"].Target) + assert.Equal(t, "schemaX", b.Config.Resources.Pipelines["pipeline5"].Target) + assert.Equal(t, "foobar", b.Config.Resources.Pipelines["pipeline6"].Target) + assert.Equal(t, "", b.Config.Resources.Pipelines["pipeline7"].Target) for _, k := range []string{"pipeline1", "pipeline2", "pipeline3", "pipeline4", "pipeline5", "pipeline6", "pipeline7"} { assert.Empty(t, b.Config.Resources.Pipelines[k].Schema)