Skip to content

Commit

Permalink
fixToMapError
Browse files Browse the repository at this point in the history
  • Loading branch information
wenzuochao committed Apr 3, 2020
1 parent 60574a9 commit 4d8a898
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion tea/tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,14 @@ func Merge(args ...interface{}) map[string]string {
}

func ToMap(args ...interface{}) map[string]interface{} {
isNotNil := false
finalArg := make(map[string]interface{})
for _, obj := range args {
if obj == nil {
continue
}
isNotNil = true

switch obj.(type) {
case map[string]string:
arg := obj.(map[string]string)
Expand Down Expand Up @@ -618,7 +624,7 @@ func ToMap(args ...interface{}) map[string]interface{} {
}
}

if len(finalArg) == 0 {
if !isNotNil {
return nil
}
return finalArg
Expand Down
4 changes: 2 additions & 2 deletions tea/tea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ func TestToMap(t *testing.T) {

invalidStr := "sdfdg"
result = ToMap(invalidStr)
utils.AssertNil(t, result)
utils.AssertEqual(t, map[string]interface{}{}, result)

result = ToMap(10)
utils.AssertNil(t, result)
utils.AssertEqual(t, map[string]interface{}{}, result)

result = ToMap(nil)
utils.AssertNil(t, result)
Expand Down

0 comments on commit 4d8a898

Please sign in to comment.