func (e mocReqValidationError) Error() string {
	cause := ""
	if e.cause != nil {
		cause = fmt.Sprintf(" | caused by: %v", e.cause)
	}
	key := ""
	if e.key {
		key = "key for "
	}
	return fmt.Sprintf(
		"invalid %sValidationError.%s: %s%s",
		key,
		e.field,
		e.reason,
		cause)
}
Error satisfies the builtin error interface
package validationerrors
import (
	"context"
	"fmt"
	"testing"
	"google.golang.org/grpc"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/metadata"
	"google.golang.org/grpc/status"
)
type DummyTransportStream struct{}
func (*DummyTransportStream) Method() string                  { return "unimplemented" }
func (*DummyTransportStream) SetHeader(md metadata.MD) error  { return nil }
func (*DummyTransportStream) SendHeader(md metadata.MD) error { return nil }
func (*DummyTransportStream) SetTrailer(md metadata.MD) error { return nil }
func DummyContextWithServerTransportStream() context.Context {
	expectedStream := &DummyTransportStream{}
	return grpc.NewContextWithServerTransportStream(context.Background(), expectedStream)
}
func TestUnaryServerInterceptor_ValidationErrors(t *testing.T) {
	ctx := DummyContextWithServerTransportStream()
	tests := []struct {
		name     string
		actual   error
		expected error
	}{
		{
			"ValidationErrorEmail",
			mocReqValidationError{
				field:  "Payload",
				reason: "embedded message failed validation",
				cause: mocReqValidationError{
					field:  "PrimaryEmail",
					reason: "value must be a valid email address",
					cause:  fmt.Errorf("mail: no angle-addr"),
					key:    true,
				},
				key: true,
			},
			&ValidationError{key: true, field: "primary_email", reason: "value must be a valid email address", cause: fmt.Errorf("mail: no angle-addr")},
		},
		{
			"ValidationErrorInt",
			mocReqValidationError{
				field:  "Payload",
				reason: "embedded message failed validation",
				cause: mocReqValidationError{
					field:  "Id",
					reason: "value must be greater than 50",
					cause:  fmt.Errorf("invalid Contact.Id"),
					key:    true,
				},
				key: true,
			},
			&ValidationError{key: true, field: "id", reason: "value must be greater than 50", cause: fmt.Errorf("invalid Contact.Id")},
		},
		{
			"ValidationErrorList",
			mocReqValidationError{
				field:  "Payload",
				reason: "embedded message failed validation",
				cause: mocReqValidationError{
					field:  "FirstName",
					reason: "value must not be in list [fizz buzz]",
					cause:  fmt.Errorf("invalid Contact.MiddleName"),
					key:    true,
				},
				key: true,
			},
			&ValidationError{key: true, field: "first_name", reason: "value must not be in list [fizz buzz]", cause: fmt.Errorf("invalid Contact.MiddleName")},
		},
		{
			"NotValidationError",
			mockNotValidation{
				Field:  "Other validator",
				Reason: "Not lyft validation",
				Key:    true,
			},
			fmt.Errorf("invalid key for Request.Other validator: Not lyft validation"),
		},
		{
			"ValidationErrorNoCause",
			mocReqValidationError{
				field:  "Payload",
				reason: "embedded message failed validation",
				key:    true,
			},
			fmt.Errorf("invalid key for ValidationError.Payload: embedded message failed validation"),
		},
		{
			"ValidationErrorBadCause",
			mocReqValidationError{
				field:  "Payload",
				reason: "embedded message failed validation",
				cause:  fmt.Errorf("Not validation"),
				key:    true,
			},
			fmt.Errorf("invalid key for ValidationError.Payload: embedded message failed validation | caused by: Not validation"),
		},
	}
	for _, tt := range tests {
		_, actual := UnaryServerInterceptor()(ctx, tt.actual, nil, nil)
		expected := tt.expected
		if actual.Error() != expected.Error() {
			t.Errorf("Error received was incorrect for test %s, expected: \"%s\", actual: \"%s\"", tt.name, expected, actual)
		}
	}
}
func TestUnaryServerInterceptor_OtherError(t *testing.T) {
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return &testResponse{}, status.Newf(codes.Internal, "Internal error").Err()
	}
	ctx := DummyContextWithServerTransportStream()
	_, actual := UnaryServerInterceptor()(ctx, nil, nil, handler)
	expected := status.Newf(codes.Internal, "Internal error")
	if actual.Error() != expected.Err().Error() {
		t.Errorf("Error received was incorrect, expected: \"%s\", actual: \"%s\"", expected.Err(), actual.Error())
	}
}
func TestUnaryServerInterceptor_Success(t *testing.T) {
	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
		return &testResponse{}, nil
	}
	ctx := DummyContextWithServerTransportStream()
	_, actual := UnaryServerInterceptor()(ctx, nil, nil, handler)
	if actual != nil {
		t.Errorf("expected no error, but got: %v", actual.Error())
	}
}
type testResponse struct{}
type mockNotValidation struct {
	Field  string
	Reason string
	Cause  error
	Key    bool
}
func (e mockNotValidation) Validate() error {
	return e
}
func (e mockNotValidation) Error() string {
	cause := ""
	if e.Cause != nil {
		cause = fmt.Sprintf(" | caused by: %v", e.Cause)
	}
	key := ""
	if e.Key {
		key = "key for "
	}
	return fmt.Sprintf(
		"invalid %sRequest.%s: %s%s",
		key,
		e.Field,
		e.Reason,
		cause)
}
var _ error = mockNotValidation{}
type mocReqValidationError struct {
	field  string
	reason string
	cause  error
	key    bool
}
func (e mocReqValidationError) Field() string { return e.field }
func (e mocReqValidationError) Reason() string { return e.reason }
func (e mocReqValidationError) Cause() error { return e.cause }
func (e mocReqValidationError) Key() bool { return e.key }
func (e mocReqValidationError) ErrorName() string {
	return "ValidationError"
}