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

Function TestRequired

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

Source from the content-addressed store, hash-verified

2180}
2181
2182func TestRequired(t *testing.T) {
2183 // The F_BoolRequired field appears after all of the required fields.
2184 // It should still be handled even after multiple required field violations.
2185 m := &pb2.GoTest{F_BoolRequired: proto.Bool(true)}
2186 got, err := proto.Marshal(m)
2187 if !isRequiredNotSetError(err) {
2188 t.Errorf("Marshal() = %v, want RequiredNotSetError error", err)
2189 }
2190 if want := []byte{0x50, 0x01}; !bytes.Equal(got, want) {
2191 t.Errorf("Marshal() = %x, want %x", got, want)
2192 }
2193
2194 m = new(pb2.GoTest)
2195 err = proto.Unmarshal(got, m)
2196 if !isRequiredNotSetError(err) {
2197 t.Errorf("Marshal() = %v, want RequiredNotSetError error", err)
2198 }
2199 if !m.GetF_BoolRequired() {
2200 t.Error("m.F_BoolRequired = false, want true")
2201 }
2202}
2203
2204func TestUnknownV2(t *testing.T) {
2205 m := new(tspb.Timestamp)

Callers

nothing calls this directly

Calls 6

GetF_BoolRequiredMethod · 0.95
BoolFunction · 0.92
MarshalFunction · 0.92
UnmarshalFunction · 0.92
isRequiredNotSetErrorFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected