fix bug identifying StringMapStringSlice

This commit is contained in:
Joshua Rubin 2016-06-07 20:49:06 -06:00
parent 27b586b42e
commit 1432793759
No known key found for this signature in database
GPG Key ID: 7E86D83E7AD27F82
2 changed files with 9 additions and 2 deletions

View File

@ -107,6 +107,8 @@ func TestMaps(t *testing.T) {
var stringMapStringSliceMultiple = map[string][]string{"key 1": []string{"value 1", "value 2", "value 3"}, "key 2": []string{"value 1", "value 2", "value 3"}, "key 3": []string{"value 1", "value 2", "value 3"}}
var stringMapStringSliceSingle = map[string][]string{"key 1": []string{"value 1"}, "key 2": []string{"value 2"}, "key 3": []string{"value 3"}}
var stringMapStringInterfaceString = map[string]interface{}{"key 1": []string{"value 1", "value 2", "value 3"}, "key 2": []string{"value 1", "value 2", "value 3"}, "key 3": []string{"value 1", "value 2", "value 3"}}
var stringMapStringInterface = map[string]interface{}{"key 1": []interface{}{"value 1", "value 2", "value 3"}, "key 2": []interface{}{"value 1", "value 2", "value 3"}, "key 3": []interface{}{"value 1", "value 2", "value 3"}}
assert.Equal(t, ToStringMap(taxonomies), map[string]interface{}{"tag": "tags", "group": "groups"})
assert.Equal(t, ToStringMapBool(stringMapBool), map[string]bool{"v1": true, "v2": false})
@ -121,7 +123,8 @@ func TestMaps(t *testing.T) {
assert.Equal(t, ToStringMapStringSlice(stringMapStringSlice), stringMapStringSlice)
assert.Equal(t, ToStringMapStringSlice(stringMapInterfaceSlice), stringMapStringSlice)
assert.Equal(t, ToStringMapStringSlice(stringMapStringSliceMultiple), stringMapStringSlice)
assert.Equal(t, ToStringMapStringSlice(stringMapStringSliceMultiple), stringMapStringSlice)
assert.Equal(t, ToStringMapStringSlice(stringMapStringInterfaceString), stringMapStringSlice)
assert.Equal(t, ToStringMapStringSlice(stringMapStringInterface), stringMapStringSlice)
assert.Equal(t, ToStringMapStringSlice(stringMapString), stringMapStringSliceSingle)
assert.Equal(t, ToStringMapStringSlice(stringMapInterface), stringMapStringSliceSingle)
assert.Equal(t, ToStringMapStringSlice(interfaceMapStringSlice), stringMapStringSlice)

View File

@ -310,8 +310,12 @@ func ToStringMapStringSliceE(i interface{}) (map[string][]string, error) {
}
case map[string]interface{}:
for k, val := range v {
if reflect.TypeOf(val).Kind() == reflect.Slice {
m[ToString(k)] = ToStringSlice(val)
} else {
m[ToString(k)] = []string{ToString(val)}
}
}
return m, nil
case map[interface{}][]string:
for k, val := range v {