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

Function TestNilExtension

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

Source from the content-addressed store, hash-verified

424}
425
426func TestNilExtension(t *testing.T) {
427 msg := &pb2.MyMessage{
428 Count: proto.Int32(1),
429 }
430 if err := proto.SetExtension(msg, pb2.E_Ext_Text, proto.String("hello")); err != nil {
431 t.Fatal(err)
432 }
433 if err := proto.SetExtension(msg, pb2.E_Ext_More, (*pb2.Ext)(nil)); err == nil {
434 t.Error("expected SetExtension to fail due to a nil extension")
435 } else if want := fmt.Sprintf("proto: SetExtension called with nil value of type %T", new(pb2.Ext)); err.Error() != want {
436 t.Errorf("expected error %v, got %v", want, err)
437 }
438 // Note: if the behavior of Marshal is ever changed to ignore nil extensions, update
439 // this test to verify that E_Ext_Text is properly propagated through marshal->unmarshal.
440}
441
442func TestMarshalUnmarshalRepeatedExtension(t *testing.T) {
443 // Add a repeated extension to the result.

Callers

nothing calls this directly

Calls 4

Int32Function · 0.92
SetExtensionFunction · 0.92
StringFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected