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

Function TestJSONPbEncoder

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

Source from the content-addressed store, hash-verified

270}
271
272func TestJSONPbEncoder(t *testing.T) {
273 msg := examplepb.ABitOfEverything{
274 SingleNested: &examplepb.ABitOfEverything_Nested{},
275 RepeatedStringValue: []string{},
276 MappedStringValue: map[string]string{},
277 MappedNestedValue: map[string]*examplepb.ABitOfEverything_Nested{},
278 RepeatedEnumValue: []examplepb.NumericEnum{},
279 TimestampValue: &timestamppb.Timestamp{},
280 Uuid: "6EC2446F-7E89-4127-B3E6-5C05E6BECBA7",
281 Nested: []*examplepb.ABitOfEverything_Nested{
282 {
283 Name: "foo",
284 Amount: 12345,
285 },
286 },
287 Uint64Value: 0xFFFFFFFFFFFFFFFF,
288 OneofValue: &examplepb.ABitOfEverything_OneofString{
289 OneofString: "bar",
290 },
291 MapValue: map[string]examplepb.NumericEnum{
292 "a": examplepb.NumericEnum_ONE,
293 "b": examplepb.NumericEnum_ZERO,
294 },
295 RepeatedEnumAnnotation: []examplepb.NumericEnum{},
296 EnumValueAnnotation: examplepb.NumericEnum_ONE,
297 RepeatedStringAnnotation: []string{},
298 RepeatedNestedAnnotation: []*examplepb.ABitOfEverything_Nested{},
299 NestedAnnotation: &examplepb.ABitOfEverything_Nested{},
300 }
301
302 for i, spec := range []struct {
303 useEnumNumbers, emitUnpopulated bool
304 indent string
305 useProtoNames bool
306 verifier func(json string)
307 }{
308 {
309 verifier: func(json string) {
310 if !strings.Contains(json, "ONE") {
311 t.Errorf(`strings.Contains(%q, "ONE") = false; want true`, json)
312 }
313 if want := "uint64Value"; !strings.Contains(json, want) {
314 t.Errorf(`strings.Contains(%q, %q) = false; want true`, json, want)
315 }
316 },
317 },
318 {
319 useEnumNumbers: true,
320 verifier: func(json string) {
321 if strings.Contains(json, "ONE") {
322 t.Errorf(`strings.Contains(%q, "ONE") = true; want false`, json)
323 }
324 },
325 },
326 {
327 emitUnpopulated: true,
328 verifier: func(json string) {
329 if want := `"sfixed32Value"`; !strings.Contains(json, want) {

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected