MCPcopy
hub / github.com/golang/protobuf / TestExtensionDescsWithUnregisteredExtensions

Function TestExtensionDescsWithUnregisteredExtensions

proto/extensions_test.go:131–171  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

129}
130
131func TestExtensionDescsWithUnregisteredExtensions(t *testing.T) {
132 msg := &pb2.MyMessage{Count: proto.Int32(0)}
133 extdesc1 := pb2.E_Ext_More
134 if descs, err := proto.ExtensionDescs(msg); len(descs) != 0 || err != nil {
135 t.Errorf("proto.ExtensionDescs: got %d descs, error %v; want 0, nil", len(descs), err)
136 }
137
138 ext1 := &pb2.Ext{}
139 if err := proto.SetExtension(msg, extdesc1, ext1); err != nil {
140 t.Fatalf("Could not set ext1: %s", err)
141 }
142 extdesc2 := &proto.ExtensionDesc{
143 ExtendedType: (*pb2.MyMessage)(nil),
144 ExtensionType: (*bool)(nil),
145 Field: 123456789,
146 Name: "a.b",
147 Tag: "varint,123456789,opt",
148 }
149 ext2 := proto.Bool(false)
150 if err := proto.SetExtension(msg, extdesc2, ext2); err != nil {
151 t.Fatalf("Could not set ext2: %s", err)
152 }
153
154 b, err := proto.Marshal(msg)
155 if err != nil {
156 t.Fatalf("Could not marshal msg: %v", err)
157 }
158 if err := proto.Unmarshal(b, msg); err != nil {
159 t.Fatalf("Could not unmarshal into msg: %v", err)
160 }
161
162 descs, err := proto.ExtensionDescs(msg)
163 if err != nil {
164 t.Fatalf("proto.ExtensionDescs: got error %v", err)
165 }
166 sortExtDescs(descs)
167 wantDescs := []*proto.ExtensionDesc{extdesc1, {Field: extdesc2.Field}}
168 if !reflect.DeepEqual(descs, wantDescs) {
169 t.Errorf("proto.ExtensionDescs(msg) sorted extension ids: got %+v, want %+v", descs, wantDescs)
170 }
171}
172
173type ExtensionDescSlice []*proto.ExtensionDesc
174

Callers

nothing calls this directly

Calls 7

Int32Function · 0.92
ExtensionDescsFunction · 0.92
SetExtensionFunction · 0.92
BoolFunction · 0.92
MarshalFunction · 0.92
UnmarshalFunction · 0.92
sortExtDescsFunction · 0.85

Tested by

no test coverage detected