forked from aws/aws-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
private/protocola/json/jsonutil: Fix Unmarshal map[string]bool (aws#320)
Fixes the JSON unmarshaling of maps of bools. The unmarshal case was missing the condition for bool value, in addition the bool pointer. Fix aws#319
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package jsonutil | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"reflect" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestUnmarshal(t *testing.T) { | ||
type scalarMaps struct { | ||
Bools map[string]bool | ||
Strings map[string]string | ||
Int64s map[string]int64 | ||
Float64s map[string]float64 | ||
Times map[string]time.Time | ||
} | ||
|
||
cases := map[string]struct { | ||
Input json.RawMessage | ||
Output interface{} | ||
Expect interface{} | ||
}{ | ||
"scalar maps": { | ||
Input: json.RawMessage(` | ||
{ | ||
"Bools": {"a": true}, | ||
"Strings": {"b": "123"}, | ||
"Int64s": {"c": 456}, | ||
"Float64s": {"d": 789}, | ||
"Times": {"e": 1257894000} | ||
}`), | ||
Output: &scalarMaps{}, | ||
Expect: &scalarMaps{ | ||
Bools: map[string]bool{"a": true}, | ||
Strings: map[string]string{"b": "123"}, | ||
Int64s: map[string]int64{"c": 456}, | ||
Float64s: map[string]float64{"d": 789}, | ||
Times: map[string]time.Time{"e": time.Unix(1257894000, 0).UTC()}, | ||
}, | ||
}, | ||
} | ||
|
||
for name, c := range cases { | ||
t.Run(name, func(t *testing.T) { | ||
err := UnmarshalJSON(c.Output, bytes.NewReader(c.Input)) | ||
if err != nil { | ||
t.Fatalf("expect no error, got %v", err) | ||
} | ||
|
||
if e, a := c.Expect, c.Output; !reflect.DeepEqual(e, a) { | ||
t.Errorf("expect:\n%#v\nactual:\n%#v\n", e, a) | ||
} | ||
}) | ||
} | ||
} |