Fix config handling with empty config entries after merge

Fixes #8701
This commit is contained in:
Bjørn Erik Pedersen
2021-06-27 13:24:49 +02:00
parent 923dd9d1c1
commit 19aa95fc7f
4 changed files with 58 additions and 5 deletions

View File

@@ -52,6 +52,24 @@ func (p Params) Set(pp Params) {
}
}
// IsZero returns true if p is considered empty.
func (p Params) IsZero() bool {
if p == nil || len(p) == 0 {
return true
}
if len(p) > 1 {
return false
}
for k, _ := range p {
return k == mergeStrategyKey
}
return false
}
// Merge transfers values from pp to p for new keys.
// This is done recursively.
func (p Params) Merge(pp Params) {
@@ -82,12 +100,9 @@ func (p Params) merge(ps ParamsMergeStrategy, pp Params) {
if pv, ok := v.(Params); ok {
vvv.merge(ms, pv)
}
}
} else if !noUpdate {
p[k] = v
}
}

View File

@@ -156,3 +156,15 @@ func TestParamsSetAndMerge(t *testing.T) {
})
}
func TestParamsIsZero(t *testing.T) {
c := qt.New(t)
var nilParams Params
c.Assert(Params{}.IsZero(), qt.IsTrue)
c.Assert(nilParams.IsZero(), qt.IsTrue)
c.Assert(Params{"foo": "bar"}.IsZero(), qt.IsFalse)
c.Assert(Params{"_merge": "foo", "foo": "bar"}.IsZero(), qt.IsFalse)
c.Assert(Params{"_merge": "foo"}.IsZero(), qt.IsTrue)
}