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

Function TestGetExtensionStability

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

Source from the content-addressed store, hash-verified

218}
219
220func TestGetExtensionStability(t *testing.T) {
221 check := func(m *pb.MyMessage) bool {
222 ext1, err := proto.GetExtension(m, pb.E_Ext_More)
223 if err != nil {
224 t.Fatalf("GetExtension() failed: %s", err)
225 }
226 ext2, err := proto.GetExtension(m, pb.E_Ext_More)
227 if err != nil {
228 t.Fatalf("GetExtension() failed: %s", err)
229 }
230 return ext1 == ext2
231 }
232 msg := &pb.MyMessage{Count: proto.Int32(4)}
233 ext0 := &pb.Ext{}
234 if err := proto.SetExtension(msg, pb.E_Ext_More, ext0); err != nil {
235 t.Fatalf("Could not set ext1: %s", ext0)
236 }
237 if !check(msg) {
238 t.Errorf("GetExtension() not stable before marshaling")
239 }
240 bb, err := proto.Marshal(msg)
241 if err != nil {
242 t.Fatalf("Marshal() failed: %s", err)
243 }
244 msg1 := &pb.MyMessage{}
245 err = proto.Unmarshal(bb, msg1)
246 if err != nil {
247 t.Fatalf("Unmarshal() failed: %s", err)
248 }
249 if !check(msg1) {
250 t.Errorf("GetExtension() not stable after unmarshaling")
251 }
252}
253
254func TestGetExtensionDefaults(t *testing.T) {
255 var setFloat64 float64 = 1

Callers

nothing calls this directly

Calls 6

GetExtensionFunction · 0.92
Int32Function · 0.92
SetExtensionFunction · 0.92
MarshalFunction · 0.92
UnmarshalFunction · 0.92
checkFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…