Append slices when importing config files

Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
This commit is contained in:
Maksym Pavlenko 2019-08-23 10:12:19 -07:00
parent bca0857530
commit 19cd0a4f12
2 changed files with 12 additions and 11 deletions

View File

@ -292,17 +292,15 @@ func resolveImports(parent string, imports []string) ([]string, error) {
}
// mergeConfig merges Config structs with the following rules:
// 'to' 'from' 'result' overwrite?
// "" "value" "value" yes
// "value" "" "value" no
// 1 0 1 no
// 0 1 1 yes
// []{"1"} []{"2"} []{"2"} yes
// []{"1"} []{} []{"1"} no
// 'to' 'from' 'result'
// "" "value" "value"
// "value" "" "value"
// 1 0 1
// 0 1 1
// []{"1"} []{"2"} []{"1","2"}
// []{"1"} []{} []{"1"}
func mergeConfig(to, from *Config) error {
return mergo.Merge(to, from, func(config *mergo.Config) {
config.Overwrite = true
})
return mergo.Merge(to, from, mergo.WithOverride, mergo.WithAppendSlice)
}
// V1DisabledFilter matches based on ID

View File

@ -35,12 +35,14 @@ func TestMergeConfigs(t *testing.T) {
DisabledPlugins: []string{"old_plugin"},
State: "old_state",
OOMScore: 1,
Timeouts: map[string]string{"a": "1"},
}
b := &Config{
Root: "new_root",
RequiredPlugins: []string{"new_plugin1", "new_plugin2"},
OOMScore: 2,
Timeouts: map[string]string{"b": "2"},
}
err := mergeConfig(a, b)
@ -50,8 +52,9 @@ func TestMergeConfigs(t *testing.T) {
assert.Equal(t, a.Root, "new_root")
assert.Equal(t, a.State, "old_state")
assert.Equal(t, a.OOMScore, 2)
assert.DeepEqual(t, a.RequiredPlugins, []string{"new_plugin1", "new_plugin2"})
assert.DeepEqual(t, a.RequiredPlugins, []string{"old_plugin", "new_plugin1", "new_plugin2"})
assert.DeepEqual(t, a.DisabledPlugins, []string{"old_plugin"})
assert.DeepEqual(t, a.Timeouts, map[string]string{"a": "1", "b": "2"})
}
func TestResolveImports(t *testing.T) {