(t *testing.T)
| 1717 | } |
| 1718 | |
| 1719 | func 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 | |
| 1776 | func TestRequiredNotSetErrorWithBadWireTypes(t *testing.T) { |
nothing calls this directly
no test coverage detected