Fix backwards compatibility

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
pull/10336/merge
Martin Hickey 2 years ago
parent a59e584684
commit b6fef6c466

@ -278,14 +278,14 @@ func (t *parser) key(data map[string]interface{}, nestedNameLevel int) (reterr e
} }
// Recurse // Recurse
if e := t.key(inner, nestedNameLevel); e != nil { e := t.key(inner, nestedNameLevel)
return e if e == nil && len(inner) == 0 {
}
if len(inner) == 0 {
return errors.Errorf("key map %q has no value", string(k)) return errors.Errorf("key map %q has no value", string(k))
} }
if len(inner) != 0 {
set(data, string(k), inner) set(data, string(k), inner)
return nil }
return e
} }
} }
} }

@ -248,9 +248,8 @@ func TestParseSet(t *testing.T) {
err: true, err: true,
}, },
{ {
"name1.name2=", str: "name1.name2=",
map[string]interface{}{}, expect: map[string]interface{}{"name1": map[string]interface{}{"name2": ""}},
false,
}, },
{ {
str: "name1.=name2", str: "name1.=name2",
@ -770,15 +769,19 @@ func TestParseSetNestedLevels(t *testing.T) {
str string str string
expect map[string]interface{} expect map[string]interface{}
err bool err bool
errStr string
}{ }{
{ {
"outer.middle.inner=value", "outer.middle.inner=value",
map[string]interface{}{"outer": map[string]interface{}{"middle": map[string]interface{}{"inner": "value"}}}, map[string]interface{}{"outer": map[string]interface{}{"middle": map[string]interface{}{"inner": "value"}}},
false, false,
"",
}, },
{ {
str: keyMultipleNestedLevels + "=value", str: keyMultipleNestedLevels + "=value",
err: true, err: true,
errStr: fmt.Sprintf("value name nested level is greater than maximum supported nested level of %d",
MaxNestedNameLevel),
}, },
} }
@ -786,6 +789,11 @@ func TestParseSetNestedLevels(t *testing.T) {
got, err := Parse(tt.str) got, err := Parse(tt.str)
if err != nil { if err != nil {
if tt.err { if tt.err {
if tt.errStr != "" {
if err.Error() != tt.errStr {
t.Errorf("Expected error: %s. Got error: %s", tt.errStr, err.Error())
}
}
continue continue
} }
t.Fatalf("%s: %s", tt.str, err) t.Fatalf("%s: %s", tt.str, err)

Loading…
Cancel
Save