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

Function TestJSONPbMarshal

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

Source from the content-addressed store, hash-verified

21)
22
23func TestJSONPbMarshal(t *testing.T) {
24 msg := examplepb.ABitOfEverything{
25 SingleNested: &examplepb.ABitOfEverything_Nested{},
26 RepeatedStringValue: []string{},
27 MappedStringValue: map[string]string{},
28 MappedNestedValue: map[string]*examplepb.ABitOfEverything_Nested{},
29 RepeatedEnumValue: []examplepb.NumericEnum{},
30 TimestampValue: &timestamppb.Timestamp{},
31 Uuid: "6EC2446F-7E89-4127-B3E6-5C05E6BECBA7",
32 Nested: []*examplepb.ABitOfEverything_Nested{
33 {
34 Name: "foo",
35 Amount: 12345,
36 },
37 },
38 Uint64Value: 0xFFFFFFFFFFFFFFFF,
39 EnumValue: examplepb.NumericEnum_ONE,
40 OneofValue: &examplepb.ABitOfEverything_OneofString{
41 OneofString: "bar",
42 },
43 MapValue: map[string]examplepb.NumericEnum{
44 "a": examplepb.NumericEnum_ONE,
45 "b": examplepb.NumericEnum_ZERO,
46 },
47 RepeatedEnumAnnotation: []examplepb.NumericEnum{},
48 EnumValueAnnotation: examplepb.NumericEnum_ONE,
49 RepeatedStringAnnotation: []string{},
50 RepeatedNestedAnnotation: []*examplepb.ABitOfEverything_Nested{},
51 NestedAnnotation: &examplepb.ABitOfEverything_Nested{},
52 }
53
54 for i, spec := range []struct {
55 useEnumNumbers, emitUnpopulated bool
56 indent string
57 useProtoNames bool
58 verifier func(json string)
59 }{
60 {
61 verifier: func(json string) {
62 if !strings.Contains(json, "ONE") {
63 t.Errorf(`strings.Contains(%q, "ONE") = false; want true`, json)
64 }
65 if want := "uint64Value"; !strings.Contains(json, want) {
66 t.Errorf(`strings.Contains(%q, %q) = false; want true`, json, want)
67 }
68 },
69 },
70 {
71 useEnumNumbers: true,
72 verifier: func(json string) {
73 if strings.Contains(json, "ONE") {
74 t.Errorf(`strings.Contains(%q, "ONE") = true; want false`, json)
75 }
76 },
77 },
78 {
79 emitUnpopulated: true,
80 verifier: func(json string) {

Callers

nothing calls this directly

Calls 2

MarshalMethod · 0.95
UnmarshalMethod · 0.65

Tested by

no test coverage detected