helper/schema: FieldReaderMap should mark map as exists if anything set

This commit is contained in:
Mitchell Hashimoto 2015-04-21 22:11:00 +02:00
parent fa934d96d0
commit 9c10a89cf8
2 changed files with 14 additions and 2 deletions

View File

@ -56,10 +56,11 @@ func (r *MapFieldReader) readMap(k string) (FieldReadResult, error) {
prefix := k + "."
r.Map.Range(func(k, v string) bool {
if strings.HasPrefix(k, prefix) {
resultSet = true
key := k[len(prefix):]
if key != "#" {
result[key] = v
resultSet = true
}
}

View File

@ -49,11 +49,14 @@ func TestMapFieldReader(t *testing.T) {
func TestMapFieldReader_extra(t *testing.T) {
r := &MapFieldReader{
Schema: map[string]*Schema{
"mapDel": &Schema{Type: TypeMap},
"mapDel": &Schema{Type: TypeMap},
"mapEmpty": &Schema{Type: TypeMap},
},
Map: BasicMapReader(map[string]string{
"mapDel": "",
"mapEmpty.#": "0",
}),
}
@ -71,6 +74,14 @@ func TestMapFieldReader_extra(t *testing.T) {
false,
false,
},
"mapEmpty": {
[]string{"mapEmpty"},
map[string]interface{}{},
true,
false,
false,
},
}
for name, tc := range cases {