Skip to content

Commit

Permalink
Fix merging context/datasources config
Browse files Browse the repository at this point in the history
  • Loading branch information
paddycarey authored and hairyhenderson committed Mar 22, 2022
1 parent 1a084d9 commit 7d39797
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/config/configfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,16 @@ func (c *Config) MergeFrom(o *Config) *Config {
if !isZero(o.Templates) {
c.Templates = o.Templates
}
mergeDataSources(c.DataSources, o.DataSources)
mergeDataSources(c.Context, o.Context)
if c.DataSources == nil {
c.DataSources = o.DataSources
} else {
mergeDataSources(c.DataSources, o.DataSources)
}
if c.Context == nil {
c.Context = o.Context
} else {
mergeDataSources(c.Context, o.Context)
}
if len(o.Plugins) > 0 {
for k, v := range o.Plugins {
c.Plugins[k] = v
Expand Down
55 changes: 55 additions & 0 deletions internal/config/configfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,61 @@ func TestMergeFrom(t *testing.T) {
}

assert.EqualValues(t, expected, cfg.MergeFrom(other))

cfg = &Config{
Input: "hello world",
OutMode: "644",
}
other = &Config{
OutputFiles: []string{"out.txt"},
Context: map[string]DataSource{
"foo": {
URL: mustURL("https://example.com/foo.yaml"),
Header: http.Header{
"Accept": {"application/json"},
},
},
"bar": {URL: mustURL("stdin:///")},
},
DataSources: map[string]DataSource{
"data": {
URL: mustURL("file:///data.json"),
},
"moredata": {
URL: mustURL("https://example.com/more.json"),
Header: http.Header{
"Authorization": {"Bearer abcd1234"},
},
},
},
}
expected = &Config{
Input: "hello world",
OutputFiles: []string{"out.txt"},
Context: map[string]DataSource{
"foo": {
URL: mustURL("https://example.com/foo.yaml"),
Header: http.Header{
"Accept": {"application/json"},
},
},
"bar": {URL: mustURL("stdin:///")},
},
DataSources: map[string]DataSource{
"data": {
URL: mustURL("file:///data.json"),
},
"moredata": {
URL: mustURL("https://example.com/more.json"),
Header: http.Header{
"Authorization": {"Bearer abcd1234"},
},
},
},
OutMode: "644",
}

assert.EqualValues(t, expected, cfg.MergeFrom(other))
}

func TestParseDataSourceFlags(t *testing.T) {
Expand Down

0 comments on commit 7d39797

Please sign in to comment.