Skip to content

Commit 19cd0a4

Browse files
committed
Append slices when importing config files
Signed-off-by: Maksym Pavlenko <[email protected]>
1 parent bca0857 commit 19cd0a4

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

services/server/config/config.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,15 @@ func resolveImports(parent string, imports []string) ([]string, error) {
292292
}
293293

294294
// mergeConfig merges Config structs with the following rules:
295-
// 'to' 'from' 'result' overwrite?
296-
// "" "value" "value" yes
297-
// "value" "" "value" no
298-
// 1 0 1 no
299-
// 0 1 1 yes
300-
// []{"1"} []{"2"} []{"2"} yes
301-
// []{"1"} []{} []{"1"} no
295+
// 'to' 'from' 'result'
296+
// "" "value" "value"
297+
// "value" "" "value"
298+
// 1 0 1
299+
// 0 1 1
300+
// []{"1"} []{"2"} []{"1","2"}
301+
// []{"1"} []{} []{"1"}
302302
func mergeConfig(to, from *Config) error {
303-
return mergo.Merge(to, from, func(config *mergo.Config) {
304-
config.Overwrite = true
305-
})
303+
return mergo.Merge(to, from, mergo.WithOverride, mergo.WithAppendSlice)
306304
}
307305

308306
// V1DisabledFilter matches based on ID

services/server/config/config_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ func TestMergeConfigs(t *testing.T) {
3535
DisabledPlugins: []string{"old_plugin"},
3636
State: "old_state",
3737
OOMScore: 1,
38+
Timeouts: map[string]string{"a": "1"},
3839
}
3940

4041
b := &Config{
4142
Root: "new_root",
4243
RequiredPlugins: []string{"new_plugin1", "new_plugin2"},
4344
OOMScore: 2,
45+
Timeouts: map[string]string{"b": "2"},
4446
}
4547

4648
err := mergeConfig(a, b)
@@ -50,8 +52,9 @@ func TestMergeConfigs(t *testing.T) {
5052
assert.Equal(t, a.Root, "new_root")
5153
assert.Equal(t, a.State, "old_state")
5254
assert.Equal(t, a.OOMScore, 2)
53-
assert.DeepEqual(t, a.RequiredPlugins, []string{"new_plugin1", "new_plugin2"})
55+
assert.DeepEqual(t, a.RequiredPlugins, []string{"old_plugin", "new_plugin1", "new_plugin2"})
5456
assert.DeepEqual(t, a.DisabledPlugins, []string{"old_plugin"})
57+
assert.DeepEqual(t, a.Timeouts, map[string]string{"a": "1", "b": "2"})
5558
}
5659

5760
func TestResolveImports(t *testing.T) {

0 commit comments

Comments
 (0)