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

Function TestClearAllExtensions

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

Source from the content-addressed store, hash-verified

582}
583
584func TestClearAllExtensions(t *testing.T) {
585 // unregistered extension
586 desc := &proto.ExtensionDesc{
587 ExtendedType: (*pb2.MyMessage)(nil),
588 ExtensionType: (*bool)(nil),
589 Field: 101010100,
590 Name: "emptyextension",
591 Tag: "varint,0,opt",
592 }
593 m := &pb2.MyMessage{}
594 if proto.HasExtension(m, desc) {
595 t.Errorf("proto.HasExtension(%s): got true, want false", proto.MarshalTextString(m))
596 }
597 if err := proto.SetExtension(m, desc, proto.Bool(true)); err != nil {
598 t.Errorf("proto.SetExtension(m, desc, true): got error %q, want nil", err)
599 }
600 if !proto.HasExtension(m, desc) {
601 t.Errorf("proto.HasExtension(%s): got false, want true", proto.MarshalTextString(m))
602 }
603 proto.ClearAllExtensions(m)
604 if proto.HasExtension(m, desc) {
605 t.Errorf("proto.HasExtension(%s): got true, want false", proto.MarshalTextString(m))
606 }
607}
608
609func TestMarshalRace(t *testing.T) {
610 ext := &pb2.Ext{}

Callers

nothing calls this directly

Calls 5

HasExtensionFunction · 0.92
MarshalTextStringFunction · 0.92
SetExtensionFunction · 0.92
BoolFunction · 0.92
ClearAllExtensionsFunction · 0.92

Tested by

no test coverage detected