(t *testing.T)
| 387 | } |
| 388 | |
| 389 | func TestExtensionsRoundTrip(t *testing.T) { |
| 390 | msg := &pb2.MyMessage{} |
| 391 | ext1 := &pb2.Ext{ |
| 392 | Data: proto.String("hi"), |
| 393 | } |
| 394 | ext2 := &pb2.Ext{ |
| 395 | Data: proto.String("there"), |
| 396 | } |
| 397 | exists := proto.HasExtension(msg, pb2.E_Ext_More) |
| 398 | if exists { |
| 399 | t.Error("Extension More present unexpectedly") |
| 400 | } |
| 401 | if err := proto.SetExtension(msg, pb2.E_Ext_More, ext1); err != nil { |
| 402 | t.Error(err) |
| 403 | } |
| 404 | if err := proto.SetExtension(msg, pb2.E_Ext_More, ext2); err != nil { |
| 405 | t.Error(err) |
| 406 | } |
| 407 | e, err := proto.GetExtension(msg, pb2.E_Ext_More) |
| 408 | if err != nil { |
| 409 | t.Error(err) |
| 410 | } |
| 411 | x, ok := e.(*pb2.Ext) |
| 412 | if !ok { |
| 413 | t.Errorf("e has type %T, expected test_proto.Ext", e) |
| 414 | } else if *x.Data != "there" { |
| 415 | t.Errorf("SetExtension failed to overwrite, got %+v, not 'there'", x) |
| 416 | } |
| 417 | proto.ClearExtension(msg, pb2.E_Ext_More) |
| 418 | if _, err = proto.GetExtension(msg, pb2.E_Ext_More); err != proto.ErrMissingExtension { |
| 419 | t.Errorf("got %v, expected ErrMissingExtension", e) |
| 420 | } |
| 421 | if err := proto.SetExtension(msg, pb2.E_Ext_More, 12); err == nil { |
| 422 | t.Error("expected some sort of type mismatch error, got nil") |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | func TestNilExtension(t *testing.T) { |
| 427 | msg := &pb2.MyMessage{ |
nothing calls this directly
no test coverage detected