Skip to content

Commit

Permalink
populate settings map if nil (#1517)
Browse files Browse the repository at this point in the history
  • Loading branch information
lovromazgon authored May 6, 2024
1 parent 9a47dbe commit 3af1dba
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pkg/provisioning/config/enrich.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func enrichConnectors(mp []Connector, pipelineID string) []Connector {
if cfg.Name == "" {
cfg.Name = cfg.ID
}
if cfg.Settings == nil {
cfg.Settings = make(map[string]string)
}
// attach the pipelineID to the connectorID
cfg.ID = pipelineID + ":" + cfg.ID
cfg.Processors = enrichProcessors(cfg.Processors, cfg.ID)
Expand All @@ -80,6 +83,9 @@ func enrichProcessors(mp []Processor, parentID string) []Processor {
if cfg.Workers == 0 {
cfg.Workers = 1
}
if cfg.Settings == nil {
cfg.Settings = make(map[string]string)
}
cfg.ID = parentID + ":" + cfg.ID
out[i] = cfg
}
Expand Down
42 changes: 40 additions & 2 deletions pkg/provisioning/config/enrich_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
)

func TestEnrich_DefaultValues(t *testing.T) {
is := is.New(t)

testCases := []struct {
name string
have Pipeline
Expand Down Expand Up @@ -127,10 +125,50 @@ func TestEnrich_DefaultValues(t *testing.T) {
Connectors: nil,
Processors: nil,
},
}, {
name: "pipeline3",
have: Pipeline{
ID: "pipeline3",
Status: "stopped",
Description: "empty",
Connectors: []Connector{
{ID: "con1"},
},
Processors: []Processor{
{ID: "proc1"},
},
},
want: Pipeline{
ID: "pipeline3",
Status: "stopped",
Name: "pipeline3",
Description: "empty",
DLQ: DLQ{
Plugin: pipeline.DefaultDLQ.Plugin,
Settings: pipeline.DefaultDLQ.Settings,
WindowSize: &pipeline.DefaultDLQ.WindowSize,
WindowNackThreshold: &pipeline.DefaultDLQ.WindowNackThreshold,
},
Connectors: []Connector{
{
ID: "pipeline3:con1",
Name: "con1",
Settings: map[string]string{},
},
},
Processors: []Processor{
{
ID: "pipeline3:proc1",
Workers: 1,
Settings: map[string]string{},
},
},
},
}}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
is := is.New(t)
got := Enrich(tc.have)
is.Equal(got, tc.want)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ var P1P1 = &processor.Instance{
Type: processor.ParentTypePipeline,
},
Config: processor.Config{
Settings: nil,
Settings: map[string]string{},
Workers: 1,
},

Expand All @@ -101,7 +101,7 @@ var P1C2P1 = &processor.Instance{
Type: processor.ParentTypeConnector,
},
Config: processor.Config{
Settings: nil,
Settings: map[string]string{},
Workers: 1,
},

Expand Down

0 comments on commit 3af1dba

Please sign in to comment.