MCPcopy
hub / github.com/grafana/tempo / TestListToMapMarshalOperationsJSON

Function TestListToMapMarshalOperationsJSON

pkg/util/listtomap/list_to_map_test.go:58–95  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

56}
57
58func TestListToMapMarshalOperationsJSON(t *testing.T) {
59 testCases := []struct {
60 name string
61 inputJSON string
62 expectedListToMapJSON ListToMap
63 marshalledJSON string
64 }{
65 {
66 name: "empty map",
67 inputJSON: "[]",
68 expectedListToMapJSON: ListToMap{},
69 marshalledJSON: "[]",
70 },
71 {
72 name: "map with entries",
73 inputJSON: "[\"foo\"]",
74 expectedListToMapJSON: ListToMap{
75 "foo": {},
76 },
77 marshalledJSON: "[\"foo\"]",
78 },
79 }
80
81 for _, tc := range testCases {
82 t.Run(tc.name, func(t *testing.T) {
83 // JSON to struct
84 var l ListToMap
85 assert.NoError(t, json.Unmarshal([]byte(tc.inputJSON), &l))
86 assert.NotNil(t, l.GetMap())
87 assert.Equal(t, tc.expectedListToMapJSON, l)
88
89 // struct to JSON
90 bytes, err := json.Marshal(tc.expectedListToMapJSON)
91 assert.NoError(t, err)
92 assert.Equal(t, tc.marshalledJSON, string(bytes))
93 })
94 }
95}

Callers

nothing calls this directly

Calls 5

GetMapMethod · 0.95
UnmarshalMethod · 0.65
MarshalMethod · 0.65
RunMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected