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

Function TestRequiredFieldEnforcementGroups

proto/proto_test.go:1254–1268  ·  view source on GitHub ↗

Verify that absent required fields in groups cause Marshal/Unmarshal to return errors.

(t *testing.T)

Source from the content-addressed store, hash-verified

1252
1253// Verify that absent required fields in groups cause Marshal/Unmarshal to return errors.
1254func TestRequiredFieldEnforcementGroups(t *testing.T) {
1255 pb := &pb2.GoTestRequiredGroupField{Group: &pb2.GoTestRequiredGroupField_Group{}}
1256 if _, err := proto.Marshal(pb); err == nil {
1257 t.Error("marshal: expected error, got nil")
1258 } else if !isRequiredNotSetError(err) {
1259 t.Errorf("marshal: bad error type: %v", err)
1260 }
1261
1262 buf := []byte{11, 12}
1263 if err := proto.Unmarshal(buf, pb); err == nil {
1264 t.Error("unmarshal: expected error, got nil")
1265 } else if !isRequiredNotSetError(err) {
1266 t.Errorf("unmarshal: bad error type: %v", err)
1267 }
1268}
1269
1270func TestTypedNilMarshal(t *testing.T) {
1271 // A typed nil should return ErrNil and not crash.

Callers

nothing calls this directly

Calls 4

MarshalFunction · 0.92
UnmarshalFunction · 0.92
isRequiredNotSetErrorFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected