(t *testing.T)
| 553 | } |
| 554 | |
| 555 | func TestUnmarshalRepeatingNonRepeatedExtension(t *testing.T) { |
| 556 | // We may see multiple instances of the same extension in the wire |
| 557 | // format. For example, the proto compiler may encode custom options in |
| 558 | // this way. Here, we verify that we merge the extensions together. |
| 559 | tests := []struct { |
| 560 | name string |
| 561 | ext []*pb.ComplexExtension |
| 562 | }{ |
| 563 | { |
| 564 | "two fields", |
| 565 | []*pb.ComplexExtension{ |
| 566 | {First: proto.Int32(7)}, |
| 567 | {Second: proto.Int32(11)}, |
| 568 | }, |
| 569 | }, |
| 570 | { |
| 571 | "repeated field", |
| 572 | []*pb.ComplexExtension{ |
| 573 | {Third: []int32{1000}}, |
| 574 | {Third: []int32{2000}}, |
| 575 | }, |
| 576 | }, |
| 577 | { |
| 578 | "two fields and repeated field", |
| 579 | []*pb.ComplexExtension{ |
| 580 | {Third: []int32{1000}}, |
| 581 | {First: proto.Int32(9)}, |
| 582 | {Second: proto.Int32(21)}, |
| 583 | {Third: []int32{2000}}, |
| 584 | }, |
| 585 | }, |
| 586 | } |
| 587 | for _, test := range tests { |
| 588 | var buf bytes.Buffer |
| 589 | var want pb.ComplexExtension |
| 590 | |
| 591 | // Generate a serialized representation of a repeated extension |
| 592 | // by catenating bytes together. |
| 593 | for i, e := range test.ext { |
| 594 | // Merge to create the wanted proto. |
| 595 | proto.Merge(&want, e) |
| 596 | |
| 597 | // serialize the message |
| 598 | msg := new(pb.OtherMessage) |
| 599 | err := proto.SetExtension(msg, pb.E_Complex, e) |
| 600 | if err != nil { |
| 601 | t.Fatalf("[%s] Error setting extension %d: %v", test.name, i, err) |
| 602 | } |
| 603 | b, err := proto.Marshal(msg) |
| 604 | if err != nil { |
| 605 | t.Fatalf("[%s] Error marshaling message %d: %v", test.name, i, err) |
| 606 | } |
| 607 | buf.Write(b) |
| 608 | } |
| 609 | |
| 610 | // Unmarshal and read the merged proto. |
| 611 | msg2 := new(pb.OtherMessage) |
| 612 | err := proto.Unmarshal(buf.Bytes(), msg2) |
nothing calls this directly
no test coverage detected
searching dependent graphs…