package server import ( "testing" "buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate" "google.golang.org/grpc/status" ) func contains(array []*validate.Violation, err *validate.Violation) bool { for _, v := range array { if *v.FieldPath == *err.FieldPath && *v.ConstraintId == *err.ConstraintId && *v.Message == *err.Message { return true } } return false } func assertValidationErrors(t *testing.T, err error, expectedValidationErrors []*validate.Violation) { st := status.Convert(err) errDetails := st.Details() for _, detail := range errDetails { switch errorType := detail.(type) { case *validate.Violations: for _, violation := range errorType.Violations { ok := contains(expectedValidationErrors, violation) if !ok { t.Errorf("Received unexptected validation error: %v, expected %v", violation, expectedValidationErrors) } } } } }