MCPcopy
hub / github.com/grpc-ecosystem/grpc-gateway / TestJSONBuiltinEncoder

Function TestJSONBuiltinEncoder

runtime/marshal_json_test.go:130–149  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

128}
129
130func TestJSONBuiltinEncoder(t *testing.T) {
131 var m runtime.JSONBuiltin
132 msg := &examplepb.SimpleMessage{
133 Id: "foo",
134 }
135
136 var buf bytes.Buffer
137 enc := m.NewEncoder(&buf)
138 if err := enc.Encode(msg); err != nil {
139 t.Errorf("enc.Encode(%v) failed with %v; want success", msg, err)
140 }
141
142 got := new(examplepb.SimpleMessage)
143 if err := json.Unmarshal(buf.Bytes(), got); err != nil {
144 t.Errorf("json.Unmarshal(%q, got) failed with %v; want success", buf.String(), err)
145 }
146 if diff := cmp.Diff(got, msg, protocmp.Transform()); diff != "" {
147 t.Error(diff)
148 }
149}
150
151func TestJSONBuiltinEncoderFields(t *testing.T) {
152 var m runtime.JSONBuiltin

Callers

nothing calls this directly

Calls 5

NewEncoderMethod · 0.95
EncodeMethod · 0.95
UnmarshalMethod · 0.65
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected