MCPcopy Create free account
hub / github.com/aws/smithy-go / TestDeterministicMapOrder

Function TestDeterministicMapOrder

document/json/encoder_test.go:70–94  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

68}
69
70func TestDeterministicMapOrder(t *testing.T) {
71 value := struct {
72 Map map[string]string
73 }{
74 Map: map[string]string{
75 "foo": "bar",
76 "a": "b",
77 "bar": "baz",
78 "b": "c",
79 "baz": "qux",
80 "c": "d",
81 },
82 }
83 expect := `{"Map":{"a":"b","b":"c","bar":"baz","baz":"qux","c":"d","foo":"bar"}}`
84
85 encoder := json.NewEncoder()
86 actual, err := encoder.Encode(value)
87 if err != nil {
88 t.Fatal(err)
89 }
90
91 if expect != string(actual) {
92 t.Errorf("encode determinstic order:\n%q !=\n%q", expect, actual)
93 }
94}
95
96func testEncode(t *testing.T, tt testCase) {
97 t.Helper()

Callers

nothing calls this directly

Calls 3

EncodeMethod · 0.95
NewEncoderFunction · 0.92
ErrorfMethod · 0.80

Tested by

no test coverage detected