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

Function TestExtensionDescsWithUnregisteredExtensions

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

Source from the content-addressed store, hash-verified

166}
167
168func TestExtensionDescsWithUnregisteredExtensions(t *testing.T) {
169 msg := &pb.MyMessage{Count: proto.Int32(0)}
170 extdesc1 := pb.E_Ext_More
171 if descs, err := proto.ExtensionDescs(msg); len(descs) != 0 || err != nil {
172 t.Errorf("proto.ExtensionDescs: got %d descs, error %v; want 0, nil", len(descs), err)
173 }
174
175 ext1 := &pb.Ext{}
176 if err := proto.SetExtension(msg, extdesc1, ext1); err != nil {
177 t.Fatalf("Could not set ext1: %s", err)
178 }
179 extdesc2 := &proto.ExtensionDesc{
180 ExtendedType: (*pb.MyMessage)(nil),
181 ExtensionType: (*bool)(nil),
182 Field: 123456789,
183 Name: "a.b",
184 Tag: "varint,123456789,opt",
185 }
186 ext2 := proto.Bool(false)
187 if err := proto.SetExtension(msg, extdesc2, ext2); err != nil {
188 t.Fatalf("Could not set ext2: %s", err)
189 }
190
191 b, err := proto.Marshal(msg)
192 if err != nil {
193 t.Fatalf("Could not marshal msg: %v", err)
194 }
195 if err = proto.Unmarshal(b, msg); err != nil {
196 t.Fatalf("Could not unmarshal into msg: %v", err)
197 }
198
199 descs, err := proto.ExtensionDescs(msg)
200 if err != nil {
201 t.Fatalf("proto.ExtensionDescs: got error %v", err)
202 }
203 sortExtDescs(descs)
204 wantDescs := []*proto.ExtensionDesc{extdesc1, {Field: extdesc2.Field}}
205 if !reflect.DeepEqual(descs, wantDescs) {
206 t.Errorf("proto.ExtensionDescs(msg) sorted extension ids: got %+v, want %+v", descs, wantDescs)
207 }
208}
209
210type ExtensionDescSlice []*proto.ExtensionDesc
211

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…