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

Function TestRequiredNotSetError

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

Source from the content-addressed store, hash-verified

1717}
1718
1719func TestRequiredNotSetError(t *testing.T) {
1720 pb := initGoTest(false)
1721 pb.RequiredField.Label = nil
1722 pb.F_Int32Required = nil
1723 pb.F_Int64Required = nil
1724
1725 want := protopack.Message{
1726 protopack.Tag{1, protopack.VarintType}, protopack.Uvarint(7),
1727 protopack.Tag{4, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
1728 protopack.Tag{2, protopack.BytesType}, protopack.String("type"),
1729 }),
1730 protopack.Tag{10, protopack.VarintType}, protopack.Bool(true),
1731 protopack.Tag{13, protopack.Fixed32Type}, protopack.Uint32(32),
1732 protopack.Tag{14, protopack.Fixed64Type}, protopack.Uint64(64),
1733 protopack.Tag{15, protopack.VarintType}, protopack.Uvarint(3232),
1734 protopack.Tag{16, protopack.VarintType}, protopack.Uvarint(6464),
1735 protopack.Tag{17, protopack.Fixed32Type}, protopack.Float32(3232),
1736 protopack.Tag{18, protopack.Fixed64Type}, protopack.Float64(6464),
1737 protopack.Tag{19, protopack.BytesType}, protopack.String("string"),
1738 protopack.Tag{70, protopack.StartGroupType},
1739 protopack.Message{
1740 protopack.Tag{71, protopack.BytesType}, protopack.String("required"),
1741 },
1742 protopack.Tag{70, protopack.EndGroupType},
1743 protopack.Tag{101, protopack.BytesType}, protopack.Bytes("bytes"),
1744 protopack.Tag{102, protopack.VarintType}, protopack.Svarint(-32),
1745 protopack.Tag{103, protopack.VarintType}, protopack.Svarint(-64),
1746 protopack.Tag{104, protopack.Fixed32Type}, protopack.Int32(-32),
1747 protopack.Tag{105, protopack.Fixed64Type}, protopack.Int64(-64),
1748 }.Marshal()
1749
1750 got, err := proto.Marshal(pb)
1751 if !isRequiredNotSetError(err) {
1752 t.Logf("marshal-1 err = %v, want *RequiredNotSetError", err)
1753 t.Fatalf("got %q\nwant %q", got, want)
1754 }
1755 if !bytes.Equal(got, want) {
1756 t.Fatalf("got %q\nwant %q", got, want)
1757 }
1758
1759 // Now test Unmarshal by recreating the original buffer.
1760 pbd := new(pb2.GoTest)
1761 err = proto.Unmarshal(got, pbd)
1762 if !isRequiredNotSetError(err) {
1763 t.Errorf("unmarshal err = %v, want *RequiredNotSetError", err)
1764 t.Fatalf("got %q\nwant %q", got, want)
1765 }
1766 got, err = proto.Marshal(pbd)
1767 if !isRequiredNotSetError(err) {
1768 t.Errorf("marshal-2 err = %v, want *RequiredNotSetError", err)
1769 t.Fatalf("got %q\nwant %q", got, want)
1770 }
1771 if !bytes.Equal(got, want) {
1772 t.Fatalf("got %q\nwant %q", got, want)
1773 }
1774}
1775
1776func TestRequiredNotSetErrorWithBadWireTypes(t *testing.T) {

Callers

nothing calls this directly

Calls 7

MarshalFunction · 0.92
UnmarshalFunction · 0.92
initGoTestFunction · 0.85
isRequiredNotSetErrorFunction · 0.85
BytesMethod · 0.80
MarshalMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected