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

Function TestExtensionMapFieldMarshalDeterministic

proto/proto_test.go:1595–1615  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1593}
1594
1595func TestExtensionMapFieldMarshalDeterministic(t *testing.T) {
1596 m := &pb2.MyMessage{Count: proto.Int(123)}
1597 if err := proto.SetExtension(m, pb2.E_Ext_More, &pb2.Ext{MapField: map[int32]int32{1: 1, 2: 2, 3: 3, 4: 4}}); err != nil {
1598 t.Fatalf("SetExtension: %v", err)
1599 }
1600 marshal := func(m proto.Message) []byte {
1601 var b proto.Buffer
1602 b.SetDeterministic(true)
1603 if err := b.Marshal(m); err != nil {
1604 t.Fatalf("Marshal failed: %v", err)
1605 }
1606 return b.Bytes()
1607 }
1608
1609 want := marshal(m)
1610 for i := 0; i < 100; i++ {
1611 if got := marshal(m); !bytes.Equal(got, want) {
1612 t.Errorf("Marshal produced inconsistent output with determinism enabled (pass %d).\n got %v\nwant %v", i, got, want)
1613 }
1614 }
1615}
1616
1617func TestUnmarshalMergesMessages(t *testing.T) {
1618 // If a nested message occurs twice in the input,

Callers

nothing calls this directly

Calls 5

SetDeterministicMethod · 0.95
MarshalMethod · 0.95
BytesMethod · 0.95
IntFunction · 0.92
SetExtensionFunction · 0.92

Tested by

no test coverage detected