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

Function TestJSONPbEncoderFields

runtime/marshal_jsonpb_test.go:380–401  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

378}
379
380func TestJSONPbEncoderFields(t *testing.T) {
381 var m runtime.JSONPb
382 for _, fixt := range fieldFixtures {
383 var buf bytes.Buffer
384 enc := m.NewEncoder(&buf)
385 if err := enc.Encode(fixt.data); err != nil {
386 t.Errorf("enc.Encode(%#v) failed with %v; want success", fixt.data, err)
387 }
388 if got, want := buf.String(), fixt.json+string(m.Delimiter()); got != want {
389 t.Errorf("enc.Encode(%#v) = %q; want %q", fixt.data, got, want)
390 }
391 }
392
393 m.UseEnumNumbers = true
394 buf, err := m.Marshal(examplepb.NumericEnum_ONE)
395 if err != nil {
396 t.Errorf("m.Marshal(%#v) failed with %v; want success", examplepb.NumericEnum_ONE, err)
397 }
398 if got, want := string(buf), "1"; got != want {
399 t.Errorf("m.Marshal(%#v) = %q; want %q", examplepb.NumericEnum_ONE, got, want)
400 }
401}
402
403func TestJSONPbDecoder(t *testing.T) {
404 var (

Callers

nothing calls this directly

Calls 5

NewEncoderMethod · 0.95
EncodeMethod · 0.95
DelimiterMethod · 0.95
MarshalMethod · 0.95
StringMethod · 0.45

Tested by

no test coverage detected