diff --git a/.gitignore b/.gitignore index 7c7eb365..a49b78c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -go.sum pkged.go gripmock +.idea \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b46bf010..8b01cc02 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,6 +42,10 @@ WORKDIR /go/src/github.com/tokopedia/gripmock # install gripmock RUN go install -v +# remove all .pb.go generated files +# since generating go file is part of the test +RUN find . -name "*.pb.go" -delete -type f + EXPOSE 4770 4771 ENTRYPOINT ["gripmock"] diff --git a/example/multi-files/client/main.go b/example/multi-files/client/main.go index d6316e21..46bf1c33 100644 --- a/example/multi-files/client/main.go +++ b/example/multi-files/client/main.go @@ -9,6 +9,7 @@ import ( "google.golang.org/grpc" ) +//go:generate protoc --go_out=plugins=grpc:${GOPATH}/src -I=.. ../file1.proto ../file2.proto func main() { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() diff --git a/example/multi-files/entrypoint.sh b/example/multi-files/entrypoint.sh index 2a0245f2..fc3ac7f0 100755 --- a/example/multi-files/entrypoint.sh +++ b/example/multi-files/entrypoint.sh @@ -2,6 +2,10 @@ # this file is used by .github/workflows/integration-test.yml -gripmock --stub=example/multi-files/stub example/multi-files/file1.proto example/multi-files/file2.proto & +gripmock --stub=example/multi-files/stub example/multi-files/file1.proto \ + example/multi-files/file2.proto & + +# wait for generated files to be available and gripmock is up +sleep 2 go run example/multi-files/client/*.go \ No newline at end of file diff --git a/example/multi-files/file1.pb.go b/example/multi-files/file1.pb.go index f52031de..16b8074a 100644 --- a/example/multi-files/file1.pb.go +++ b/example/multi-files/file1.pb.go @@ -1,126 +1,239 @@ // Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.17.3 // source: file1.proto -package multifiles - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" +package multi_files import ( - context "golang.org/x/net/context" + context "context" grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" ) -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) // The request message containing the user's name. type Request1 struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -func (m *Request1) Reset() { *m = Request1{} } -func (m *Request1) String() string { return proto.CompactTextString(m) } -func (*Request1) ProtoMessage() {} -func (*Request1) Descriptor() ([]byte, []int) { - return fileDescriptor_file1_b87e0295d2d0c495, []int{0} -} -func (m *Request1) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Request1.Unmarshal(m, b) -} -func (m *Request1) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Request1.Marshal(b, m, deterministic) + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` } -func (dst *Request1) XXX_Merge(src proto.Message) { - xxx_messageInfo_Request1.Merge(dst, src) + +func (x *Request1) Reset() { + *x = Request1{} + if protoimpl.UnsafeEnabled { + mi := &file_file1_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } -func (m *Request1) XXX_Size() int { - return xxx_messageInfo_Request1.Size(m) + +func (x *Request1) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *Request1) XXX_DiscardUnknown() { - xxx_messageInfo_Request1.DiscardUnknown(m) + +func (*Request1) ProtoMessage() {} + +func (x *Request1) ProtoReflect() protoreflect.Message { + mi := &file_file1_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -var xxx_messageInfo_Request1 proto.InternalMessageInfo +// Deprecated: Use Request1.ProtoReflect.Descriptor instead. +func (*Request1) Descriptor() ([]byte, []int) { + return file_file1_proto_rawDescGZIP(), []int{0} +} -func (m *Request1) GetName() string { - if m != nil { - return m.Name +func (x *Request1) GetName() string { + if x != nil { + return x.Name } return "" } // The response message containing the greetings type Reply1 struct { - Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` - ReturnCode int32 `protobuf:"varint,2,opt,name=return_code,json=returnCode,proto3" json:"return_code,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -func (m *Reply1) Reset() { *m = Reply1{} } -func (m *Reply1) String() string { return proto.CompactTextString(m) } -func (*Reply1) ProtoMessage() {} -func (*Reply1) Descriptor() ([]byte, []int) { - return fileDescriptor_file1_b87e0295d2d0c495, []int{1} -} -func (m *Reply1) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Reply1.Unmarshal(m, b) -} -func (m *Reply1) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Reply1.Marshal(b, m, deterministic) + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` + ReturnCode int32 `protobuf:"varint,2,opt,name=return_code,json=returnCode,proto3" json:"return_code,omitempty"` } -func (dst *Reply1) XXX_Merge(src proto.Message) { - xxx_messageInfo_Reply1.Merge(dst, src) + +func (x *Reply1) Reset() { + *x = Reply1{} + if protoimpl.UnsafeEnabled { + mi := &file_file1_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } -func (m *Reply1) XXX_Size() int { - return xxx_messageInfo_Reply1.Size(m) + +func (x *Reply1) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *Reply1) XXX_DiscardUnknown() { - xxx_messageInfo_Reply1.DiscardUnknown(m) + +func (*Reply1) ProtoMessage() {} + +func (x *Reply1) ProtoReflect() protoreflect.Message { + mi := &file_file1_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -var xxx_messageInfo_Reply1 proto.InternalMessageInfo +// Deprecated: Use Reply1.ProtoReflect.Descriptor instead. +func (*Reply1) Descriptor() ([]byte, []int) { + return file_file1_proto_rawDescGZIP(), []int{1} +} -func (m *Reply1) GetMessage() string { - if m != nil { - return m.Message +func (x *Reply1) GetMessage() string { + if x != nil { + return x.Message } return "" } -func (m *Reply1) GetReturnCode() int32 { - if m != nil { - return m.ReturnCode +func (x *Reply1) GetReturnCode() int32 { + if x != nil { + return x.ReturnCode } return 0 } -func init() { - proto.RegisterType((*Request1)(nil), "multifiles.Request1") - proto.RegisterType((*Reply1)(nil), "multifiles.Reply1") +var File_file1_proto protoreflect.FileDescriptor + +var file_file1_proto_rawDesc = []byte{ + 0x0a, 0x0b, 0x66, 0x69, 0x6c, 0x65, 0x31, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x6d, + 0x75, 0x6c, 0x74, 0x69, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x22, 0x1e, 0x0a, 0x08, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x31, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x43, 0x0a, 0x06, 0x52, 0x65, 0x70, + 0x6c, 0x79, 0x31, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1f, 0x0a, + 0x0b, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x0a, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x43, 0x6f, 0x64, 0x65, 0x32, 0x41, + 0x0a, 0x09, 0x47, 0x72, 0x69, 0x70, 0x6d, 0x6f, 0x63, 0x6b, 0x31, 0x12, 0x34, 0x0a, 0x08, 0x53, + 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x14, 0x2e, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x66, + 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x31, 0x1a, 0x12, 0x2e, + 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x31, 0x42, 0x33, 0x5a, 0x31, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x74, 0x6f, 0x6b, 0x6f, 0x70, 0x65, 0x64, 0x69, 0x61, 0x2f, 0x67, 0x72, 0x69, 0x70, 0x6d, 0x6f, + 0x63, 0x6b, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, 0x6d, 0x75, 0x6c, 0x74, 0x69, + 0x2d, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_file1_proto_rawDescOnce sync.Once + file_file1_proto_rawDescData = file_file1_proto_rawDesc +) + +func file_file1_proto_rawDescGZIP() []byte { + file_file1_proto_rawDescOnce.Do(func() { + file_file1_proto_rawDescData = protoimpl.X.CompressGZIP(file_file1_proto_rawDescData) + }) + return file_file1_proto_rawDescData +} + +var file_file1_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_file1_proto_goTypes = []interface{}{ + (*Request1)(nil), // 0: multifiles.Request1 + (*Reply1)(nil), // 1: multifiles.Reply1 +} +var file_file1_proto_depIdxs = []int32{ + 0, // 0: multifiles.Gripmock1.SayHello:input_type -> multifiles.Request1 + 1, // 1: multifiles.Gripmock1.SayHello:output_type -> multifiles.Reply1 + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_file1_proto_init() } +func file_file1_proto_init() { + if File_file1_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_file1_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Request1); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_file1_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Reply1); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_file1_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_file1_proto_goTypes, + DependencyIndexes: file_file1_proto_depIdxs, + MessageInfos: file_file1_proto_msgTypes, + }.Build() + File_file1_proto = out.File + file_file1_proto_rawDesc = nil + file_file1_proto_goTypes = nil + file_file1_proto_depIdxs = nil } // Reference imports to suppress errors if they are not otherwise used. var _ context.Context -var _ grpc.ClientConn +var _ grpc.ClientConnInterface // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 +const _ = grpc.SupportPackageIsVersion6 // Gripmock1Client is the client API for Gripmock1 service. // @@ -131,10 +244,10 @@ type Gripmock1Client interface { } type gripmock1Client struct { - cc *grpc.ClientConn + cc grpc.ClientConnInterface } -func NewGripmock1Client(cc *grpc.ClientConn) Gripmock1Client { +func NewGripmock1Client(cc grpc.ClientConnInterface) Gripmock1Client { return &gripmock1Client{cc} } @@ -153,6 +266,14 @@ type Gripmock1Server interface { SayHello(context.Context, *Request1) (*Reply1, error) } +// UnimplementedGripmock1Server can be embedded to have forward compatible implementations. +type UnimplementedGripmock1Server struct { +} + +func (*UnimplementedGripmock1Server) SayHello(context.Context, *Request1) (*Reply1, error) { + return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") +} + func RegisterGripmock1Server(s *grpc.Server, srv Gripmock1Server) { s.RegisterService(&_Gripmock1_serviceDesc, srv) } @@ -187,20 +308,3 @@ var _Gripmock1_serviceDesc = grpc.ServiceDesc{ Streams: []grpc.StreamDesc{}, Metadata: "file1.proto", } - -func init() { proto.RegisterFile("file1.proto", fileDescriptor_file1_b87e0295d2d0c495) } - -var fileDescriptor_file1_b87e0295d2d0c495 = []byte{ - // 173 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4e, 0xcb, 0xcc, 0x49, - 0x35, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0xca, 0x2d, 0xcd, 0x29, 0xc9, 0x04, 0x89, - 0x14, 0x2b, 0xc9, 0x71, 0x71, 0x04, 0xa5, 0x16, 0x96, 0xa6, 0x16, 0x97, 0x18, 0x0a, 0x09, 0x71, - 0xb1, 0xe4, 0x25, 0xe6, 0xa6, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x81, 0xd9, 0x4a, 0xce, - 0x5c, 0x6c, 0x41, 0xa9, 0x05, 0x39, 0x95, 0x86, 0x42, 0x12, 0x5c, 0xec, 0xb9, 0xa9, 0xc5, 0xc5, - 0x89, 0xe9, 0x30, 0x05, 0x30, 0xae, 0x90, 0x3c, 0x17, 0x77, 0x51, 0x6a, 0x49, 0x69, 0x51, 0x5e, - 0x7c, 0x72, 0x7e, 0x4a, 0xaa, 0x04, 0x93, 0x02, 0xa3, 0x06, 0x6b, 0x10, 0x17, 0x44, 0xc8, 0x39, - 0x3f, 0x25, 0xd5, 0xc8, 0x91, 0x8b, 0xd3, 0xbd, 0x28, 0xb3, 0x20, 0x37, 0x3f, 0x39, 0xdb, 0x50, - 0xc8, 0x84, 0x8b, 0x23, 0x38, 0xb1, 0xd2, 0x23, 0x35, 0x27, 0x27, 0x5f, 0x48, 0x44, 0x0f, 0xe1, - 0x14, 0x3d, 0x98, 0x3b, 0xa4, 0x84, 0x50, 0x45, 0x41, 0xb6, 0x27, 0xb1, 0x81, 0x9d, 0x6e, 0x0c, - 0x08, 0x00, 0x00, 0xff, 0xff, 0xd7, 0xb7, 0x45, 0x56, 0xc9, 0x00, 0x00, 0x00, -} diff --git a/example/multi-files/file1.proto b/example/multi-files/file1.proto index 14c15042..4b9056a6 100644 --- a/example/multi-files/file1.proto +++ b/example/multi-files/file1.proto @@ -2,6 +2,7 @@ syntax = "proto3"; package multifiles; +option go_package = "github.com/tokopedia/gripmock/example/multi-files"; // The Gripmock service definition. service Gripmock1 { // simple unary method diff --git a/example/multi-files/file2.pb.go b/example/multi-files/file2.pb.go index fb0060ca..73f97bad 100644 --- a/example/multi-files/file2.pb.go +++ b/example/multi-files/file2.pb.go @@ -1,126 +1,239 @@ // Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.17.3 // source: file2.proto -package multifiles - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" +package multi_files import ( - context "golang.org/x/net/context" + context "context" grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" ) -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) // The request message containing the user's name. type Request2 struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -func (m *Request2) Reset() { *m = Request2{} } -func (m *Request2) String() string { return proto.CompactTextString(m) } -func (*Request2) ProtoMessage() {} -func (*Request2) Descriptor() ([]byte, []int) { - return fileDescriptor_file2_6a46b4869ea0a05f, []int{0} -} -func (m *Request2) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Request2.Unmarshal(m, b) -} -func (m *Request2) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Request2.Marshal(b, m, deterministic) + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` } -func (dst *Request2) XXX_Merge(src proto.Message) { - xxx_messageInfo_Request2.Merge(dst, src) + +func (x *Request2) Reset() { + *x = Request2{} + if protoimpl.UnsafeEnabled { + mi := &file_file2_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } -func (m *Request2) XXX_Size() int { - return xxx_messageInfo_Request2.Size(m) + +func (x *Request2) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *Request2) XXX_DiscardUnknown() { - xxx_messageInfo_Request2.DiscardUnknown(m) + +func (*Request2) ProtoMessage() {} + +func (x *Request2) ProtoReflect() protoreflect.Message { + mi := &file_file2_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -var xxx_messageInfo_Request2 proto.InternalMessageInfo +// Deprecated: Use Request2.ProtoReflect.Descriptor instead. +func (*Request2) Descriptor() ([]byte, []int) { + return file_file2_proto_rawDescGZIP(), []int{0} +} -func (m *Request2) GetName() string { - if m != nil { - return m.Name +func (x *Request2) GetName() string { + if x != nil { + return x.Name } return "" } // The response message containing the greetings type Reply2 struct { - Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` - ReturnCode int32 `protobuf:"varint,2,opt,name=return_code,json=returnCode,proto3" json:"return_code,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -func (m *Reply2) Reset() { *m = Reply2{} } -func (m *Reply2) String() string { return proto.CompactTextString(m) } -func (*Reply2) ProtoMessage() {} -func (*Reply2) Descriptor() ([]byte, []int) { - return fileDescriptor_file2_6a46b4869ea0a05f, []int{1} -} -func (m *Reply2) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Reply2.Unmarshal(m, b) -} -func (m *Reply2) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Reply2.Marshal(b, m, deterministic) + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` + ReturnCode int32 `protobuf:"varint,2,opt,name=return_code,json=returnCode,proto3" json:"return_code,omitempty"` } -func (dst *Reply2) XXX_Merge(src proto.Message) { - xxx_messageInfo_Reply2.Merge(dst, src) + +func (x *Reply2) Reset() { + *x = Reply2{} + if protoimpl.UnsafeEnabled { + mi := &file_file2_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } -func (m *Reply2) XXX_Size() int { - return xxx_messageInfo_Reply2.Size(m) + +func (x *Reply2) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *Reply2) XXX_DiscardUnknown() { - xxx_messageInfo_Reply2.DiscardUnknown(m) + +func (*Reply2) ProtoMessage() {} + +func (x *Reply2) ProtoReflect() protoreflect.Message { + mi := &file_file2_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -var xxx_messageInfo_Reply2 proto.InternalMessageInfo +// Deprecated: Use Reply2.ProtoReflect.Descriptor instead. +func (*Reply2) Descriptor() ([]byte, []int) { + return file_file2_proto_rawDescGZIP(), []int{1} +} -func (m *Reply2) GetMessage() string { - if m != nil { - return m.Message +func (x *Reply2) GetMessage() string { + if x != nil { + return x.Message } return "" } -func (m *Reply2) GetReturnCode() int32 { - if m != nil { - return m.ReturnCode +func (x *Reply2) GetReturnCode() int32 { + if x != nil { + return x.ReturnCode } return 0 } -func init() { - proto.RegisterType((*Request2)(nil), "multifiles.Request2") - proto.RegisterType((*Reply2)(nil), "multifiles.Reply2") +var File_file2_proto protoreflect.FileDescriptor + +var file_file2_proto_rawDesc = []byte{ + 0x0a, 0x0b, 0x66, 0x69, 0x6c, 0x65, 0x32, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x6d, + 0x75, 0x6c, 0x74, 0x69, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x22, 0x1e, 0x0a, 0x08, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x32, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x43, 0x0a, 0x06, 0x52, 0x65, 0x70, + 0x6c, 0x79, 0x32, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1f, 0x0a, + 0x0b, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x0a, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x43, 0x6f, 0x64, 0x65, 0x32, 0x41, + 0x0a, 0x09, 0x47, 0x72, 0x69, 0x70, 0x6d, 0x6f, 0x63, 0x6b, 0x32, 0x12, 0x34, 0x0a, 0x08, 0x53, + 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x14, 0x2e, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x66, + 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x32, 0x1a, 0x12, 0x2e, + 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x79, + 0x32, 0x42, 0x33, 0x5a, 0x31, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x74, 0x6f, 0x6b, 0x6f, 0x70, 0x65, 0x64, 0x69, 0x61, 0x2f, 0x67, 0x72, 0x69, 0x70, 0x6d, 0x6f, + 0x63, 0x6b, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, 0x6d, 0x75, 0x6c, 0x74, 0x69, + 0x2d, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_file2_proto_rawDescOnce sync.Once + file_file2_proto_rawDescData = file_file2_proto_rawDesc +) + +func file_file2_proto_rawDescGZIP() []byte { + file_file2_proto_rawDescOnce.Do(func() { + file_file2_proto_rawDescData = protoimpl.X.CompressGZIP(file_file2_proto_rawDescData) + }) + return file_file2_proto_rawDescData +} + +var file_file2_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_file2_proto_goTypes = []interface{}{ + (*Request2)(nil), // 0: multifiles.Request2 + (*Reply2)(nil), // 1: multifiles.Reply2 +} +var file_file2_proto_depIdxs = []int32{ + 0, // 0: multifiles.Gripmock2.SayHello:input_type -> multifiles.Request2 + 1, // 1: multifiles.Gripmock2.SayHello:output_type -> multifiles.Reply2 + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_file2_proto_init() } +func file_file2_proto_init() { + if File_file2_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_file2_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Request2); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_file2_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Reply2); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_file2_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_file2_proto_goTypes, + DependencyIndexes: file_file2_proto_depIdxs, + MessageInfos: file_file2_proto_msgTypes, + }.Build() + File_file2_proto = out.File + file_file2_proto_rawDesc = nil + file_file2_proto_goTypes = nil + file_file2_proto_depIdxs = nil } // Reference imports to suppress errors if they are not otherwise used. var _ context.Context -var _ grpc.ClientConn +var _ grpc.ClientConnInterface // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 +const _ = grpc.SupportPackageIsVersion6 // Gripmock2Client is the client API for Gripmock2 service. // @@ -131,10 +244,10 @@ type Gripmock2Client interface { } type gripmock2Client struct { - cc *grpc.ClientConn + cc grpc.ClientConnInterface } -func NewGripmock2Client(cc *grpc.ClientConn) Gripmock2Client { +func NewGripmock2Client(cc grpc.ClientConnInterface) Gripmock2Client { return &gripmock2Client{cc} } @@ -153,6 +266,14 @@ type Gripmock2Server interface { SayHello(context.Context, *Request2) (*Reply2, error) } +// UnimplementedGripmock2Server can be embedded to have forward compatible implementations. +type UnimplementedGripmock2Server struct { +} + +func (*UnimplementedGripmock2Server) SayHello(context.Context, *Request2) (*Reply2, error) { + return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") +} + func RegisterGripmock2Server(s *grpc.Server, srv Gripmock2Server) { s.RegisterService(&_Gripmock2_serviceDesc, srv) } @@ -187,20 +308,3 @@ var _Gripmock2_serviceDesc = grpc.ServiceDesc{ Streams: []grpc.StreamDesc{}, Metadata: "file2.proto", } - -func init() { proto.RegisterFile("file2.proto", fileDescriptor_file2_6a46b4869ea0a05f) } - -var fileDescriptor_file2_6a46b4869ea0a05f = []byte{ - // 173 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x8e, 0xb1, 0x0e, 0x82, 0x40, - 0x10, 0x44, 0x83, 0x51, 0x84, 0xa5, 0xdb, 0x58, 0x10, 0x0b, 0x25, 0x54, 0x54, 0x14, 0xa7, 0x3f, - 0x60, 0x28, 0xb4, 0x3e, 0x3f, 0xc0, 0x20, 0xac, 0x86, 0x78, 0xc7, 0xe2, 0xdd, 0x51, 0xf0, 0xf7, - 0x06, 0x0c, 0x31, 0x76, 0x33, 0x2f, 0x93, 0xcc, 0x83, 0xe8, 0xd1, 0x28, 0x12, 0x79, 0x67, 0xd8, - 0x31, 0x82, 0xee, 0x95, 0x6b, 0x46, 0x62, 0xd3, 0x1d, 0x04, 0x92, 0xde, 0x3d, 0x59, 0x27, 0x10, - 0x61, 0xd9, 0x96, 0x9a, 0x62, 0x2f, 0xf1, 0xb2, 0x50, 0x4e, 0x39, 0x2d, 0xc0, 0x97, 0xd4, 0xa9, - 0x41, 0x60, 0x0c, 0x6b, 0x4d, 0xd6, 0x96, 0xcf, 0x79, 0x30, 0x57, 0xdc, 0x43, 0x64, 0xc8, 0xf5, - 0xa6, 0xbd, 0x55, 0x5c, 0x53, 0xbc, 0x48, 0xbc, 0x6c, 0x25, 0xe1, 0x8b, 0x0a, 0xae, 0x49, 0x9c, - 0x20, 0x3c, 0x9b, 0xa6, 0xd3, 0x5c, 0xbd, 0x04, 0x1e, 0x21, 0xb8, 0x96, 0xc3, 0x85, 0x94, 0x62, - 0xdc, 0xe4, 0x3f, 0x95, 0x7c, 0xf6, 0xd8, 0xe2, 0x3f, 0x1d, 0xdf, 0xef, 0xfe, 0xa4, 0x7e, 0xf8, - 0x04, 0x00, 0x00, 0xff, 0xff, 0x58, 0xdc, 0x5d, 0xb0, 0xc9, 0x00, 0x00, 0x00, -} diff --git a/example/multi-files/file2.proto b/example/multi-files/file2.proto index 9139cdc9..c62380c5 100644 --- a/example/multi-files/file2.proto +++ b/example/multi-files/file2.proto @@ -2,6 +2,7 @@ syntax = "proto3"; package multifiles; +option go_package = "github.com/tokopedia/gripmock/example/multi-files"; service Gripmock2 { // simple unary method rpc SayHello (Request2) returns (Reply2); diff --git a/example/multi-package/bar/bar.pb.go b/example/multi-package/bar/bar.pb.go index a391f809..1c7beeec 100644 --- a/example/multi-package/bar/bar.pb.go +++ b/example/multi-package/bar/bar.pb.go @@ -1,72 +1,144 @@ // Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.17.3 // source: bar/bar.proto -package bar +package multi_package -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) type Bar struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -func (m *Bar) Reset() { *m = Bar{} } -func (m *Bar) String() string { return proto.CompactTextString(m) } -func (*Bar) ProtoMessage() {} -func (*Bar) Descriptor() ([]byte, []int) { - return fileDescriptor_bar_6bb46c8968cb585e, []int{0} + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` } -func (m *Bar) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Bar.Unmarshal(m, b) -} -func (m *Bar) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Bar.Marshal(b, m, deterministic) -} -func (dst *Bar) XXX_Merge(src proto.Message) { - xxx_messageInfo_Bar.Merge(dst, src) + +func (x *Bar) Reset() { + *x = Bar{} + if protoimpl.UnsafeEnabled { + mi := &file_bar_bar_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } -func (m *Bar) XXX_Size() int { - return xxx_messageInfo_Bar.Size(m) + +func (x *Bar) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *Bar) XXX_DiscardUnknown() { - xxx_messageInfo_Bar.DiscardUnknown(m) + +func (*Bar) ProtoMessage() {} + +func (x *Bar) ProtoReflect() protoreflect.Message { + mi := &file_bar_bar_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -var xxx_messageInfo_Bar proto.InternalMessageInfo +// Deprecated: Use Bar.ProtoReflect.Descriptor instead. +func (*Bar) Descriptor() ([]byte, []int) { + return file_bar_bar_proto_rawDescGZIP(), []int{0} +} -func (m *Bar) GetName() string { - if m != nil { - return m.Name +func (x *Bar) GetName() string { + if x != nil { + return x.Name } return "" } -func init() { - proto.RegisterType((*Bar)(nil), "bar.Bar") +var File_bar_bar_proto protoreflect.FileDescriptor + +var file_bar_bar_proto_rawDesc = []byte{ + 0x0a, 0x0d, 0x62, 0x61, 0x72, 0x2f, 0x62, 0x61, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, + 0x03, 0x62, 0x61, 0x72, 0x22, 0x19, 0x0a, 0x03, 0x42, 0x61, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6e, + 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x42, + 0x47, 0x5a, 0x45, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x74, 0x6f, + 0x6b, 0x6f, 0x70, 0x65, 0x64, 0x69, 0x61, 0x2f, 0x67, 0x72, 0x69, 0x70, 0x6d, 0x6f, 0x63, 0x6b, + 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x2d, 0x70, + 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x2f, 0x62, 0x61, 0x72, 0x3b, 0x6d, 0x75, 0x6c, 0x74, 0x69, + 0x5f, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_bar_bar_proto_rawDescOnce sync.Once + file_bar_bar_proto_rawDescData = file_bar_bar_proto_rawDesc +) + +func file_bar_bar_proto_rawDescGZIP() []byte { + file_bar_bar_proto_rawDescOnce.Do(func() { + file_bar_bar_proto_rawDescData = protoimpl.X.CompressGZIP(file_bar_bar_proto_rawDescData) + }) + return file_bar_bar_proto_rawDescData } -func init() { proto.RegisterFile("bar/bar.proto", fileDescriptor_bar_6bb46c8968cb585e) } +var file_bar_bar_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_bar_bar_proto_goTypes = []interface{}{ + (*Bar)(nil), // 0: bar.Bar +} +var file_bar_bar_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} -var fileDescriptor_bar_6bb46c8968cb585e = []byte{ - // 73 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4d, 0x4a, 0x2c, 0xd2, - 0x4f, 0x4a, 0x2c, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x4e, 0x4a, 0x2c, 0x52, 0x92, - 0xe4, 0x62, 0x76, 0x4a, 0x2c, 0x12, 0x12, 0xe2, 0x62, 0xc9, 0x4b, 0xcc, 0x4d, 0x95, 0x60, 0x54, - 0x60, 0xd4, 0xe0, 0x0c, 0x02, 0xb3, 0x93, 0xd8, 0xc0, 0xca, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, - 0xff, 0x7f, 0xff, 0x96, 0x64, 0x37, 0x00, 0x00, 0x00, +func init() { file_bar_bar_proto_init() } +func file_bar_bar_proto_init() { + if File_bar_bar_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_bar_bar_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Bar); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_bar_bar_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_bar_bar_proto_goTypes, + DependencyIndexes: file_bar_bar_proto_depIdxs, + MessageInfos: file_bar_bar_proto_msgTypes, + }.Build() + File_bar_bar_proto = out.File + file_bar_bar_proto_rawDesc = nil + file_bar_bar_proto_goTypes = nil + file_bar_bar_proto_depIdxs = nil } diff --git a/example/multi-package/bar/bar.proto b/example/multi-package/bar/bar.proto index 7c6f17f3..49c22ccf 100644 --- a/example/multi-package/bar/bar.proto +++ b/example/multi-package/bar/bar.proto @@ -1,8 +1,8 @@ syntax = "proto3"; package bar; -// this will be used to determine import path in gripmock's generated server -option go_package = "github.com/tokopedia/gripmock/example/multi-package/bar"; +// this go_package is simulating alias collision +option go_package = "github.com/tokopedia/gripmock/example/multi-package/bar;multi_package"; message Bar{ string name = 1; diff --git a/example/multi-package/client/main.go b/example/multi-package/client/main.go index 8531a796..0cd57ae4 100644 --- a/example/multi-package/client/main.go +++ b/example/multi-package/client/main.go @@ -7,10 +7,11 @@ import ( "time" pb "github.com/tokopedia/gripmock/example/multi-package" - "github.com/tokopedia/gripmock/example/multi-package/bar" + multi_package "github.com/tokopedia/gripmock/example/multi-package/bar" "google.golang.org/grpc" ) +//go:generate protoc --go_out=plugins=grpc:${GOPATH}/src -I=.. ../hello.proto ../foo.proto ../bar/bar.proto func main() { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() @@ -29,7 +30,7 @@ func main() { if len(os.Args) > 1 { name = os.Args[1] } - r, err := c.Greet(context.Background(), &bar.Bar{Name: name}) + r, err := c.Greet(context.Background(), &multi_package.Bar{Name: name}) if err != nil { log.Fatalf("error from grpc: %v", err) } diff --git a/example/multi-package/entrypoint.sh b/example/multi-package/entrypoint.sh index eef301c6..982ddcb1 100755 --- a/example/multi-package/entrypoint.sh +++ b/example/multi-package/entrypoint.sh @@ -4,6 +4,11 @@ # we need to add example/multi-package ar as included import path # without it protoc could not find the bar/bar.proto -gripmock --stub=example/multi-package/stub --imports=example/multi-package/ example/multi-package/foo.proto example/multi-package/hello.proto & +gripmock --stub=example/multi-package/stub --imports=example/multi-package/ \ + example/multi-package/foo.proto example/multi-package/hello.proto \ + example/multi-package/bar/bar.proto & + +# wait for generated files to be available and gripmock is up +sleep 2 go run example/multi-package/client/*.go \ No newline at end of file diff --git a/example/multi-package/foo.pb.go b/example/multi-package/foo.pb.go index e6ec0760..0ba7ff1f 100644 --- a/example/multi-package/foo.pb.go +++ b/example/multi-package/foo.pb.go @@ -1,72 +1,147 @@ // Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.17.3 // source: foo.proto -package hello +// simulating neighboring .proto file +// but different package -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" +package multi_package -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) type Response struct { - Response string `protobuf:"bytes,1,opt,name=response,proto3" json:"response,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -func (m *Response) Reset() { *m = Response{} } -func (m *Response) String() string { return proto.CompactTextString(m) } -func (*Response) ProtoMessage() {} -func (*Response) Descriptor() ([]byte, []int) { - return fileDescriptor_foo_3aa154bffd10d95b, []int{0} -} -func (m *Response) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Response.Unmarshal(m, b) + Response string `protobuf:"bytes,1,opt,name=response,proto3" json:"response,omitempty"` } -func (m *Response) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Response.Marshal(b, m, deterministic) -} -func (dst *Response) XXX_Merge(src proto.Message) { - xxx_messageInfo_Response.Merge(dst, src) + +func (x *Response) Reset() { + *x = Response{} + if protoimpl.UnsafeEnabled { + mi := &file_foo_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } -func (m *Response) XXX_Size() int { - return xxx_messageInfo_Response.Size(m) + +func (x *Response) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *Response) XXX_DiscardUnknown() { - xxx_messageInfo_Response.DiscardUnknown(m) + +func (*Response) ProtoMessage() {} + +func (x *Response) ProtoReflect() protoreflect.Message { + mi := &file_foo_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -var xxx_messageInfo_Response proto.InternalMessageInfo +// Deprecated: Use Response.ProtoReflect.Descriptor instead. +func (*Response) Descriptor() ([]byte, []int) { + return file_foo_proto_rawDescGZIP(), []int{0} +} -func (m *Response) GetResponse() string { - if m != nil { - return m.Response +func (x *Response) GetResponse() string { + if x != nil { + return x.Response } return "" } -func init() { - proto.RegisterType((*Response)(nil), "hello.Response") +var File_foo_proto protoreflect.FileDescriptor + +var file_foo_proto_rawDesc = []byte{ + 0x0a, 0x09, 0x66, 0x6f, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x03, 0x66, 0x6f, 0x6f, + 0x22, 0x26, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1a, 0x0a, 0x08, + 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, + 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x35, 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, + 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x74, 0x6f, 0x6b, 0x6f, 0x70, 0x65, 0x64, 0x69, 0x61, + 0x2f, 0x67, 0x72, 0x69, 0x70, 0x6d, 0x6f, 0x63, 0x6b, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, + 0x65, 0x2f, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x2d, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_foo_proto_rawDescOnce sync.Once + file_foo_proto_rawDescData = file_foo_proto_rawDesc +) + +func file_foo_proto_rawDescGZIP() []byte { + file_foo_proto_rawDescOnce.Do(func() { + file_foo_proto_rawDescData = protoimpl.X.CompressGZIP(file_foo_proto_rawDescData) + }) + return file_foo_proto_rawDescData } -func init() { proto.RegisterFile("foo.proto", fileDescriptor_foo_3aa154bffd10d95b) } +var file_foo_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_foo_proto_goTypes = []interface{}{ + (*Response)(nil), // 0: foo.Response +} +var file_foo_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} -var fileDescriptor_foo_3aa154bffd10d95b = []byte{ - // 75 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4c, 0xcb, 0xcf, 0xd7, - 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xcd, 0x48, 0xcd, 0xc9, 0xc9, 0x57, 0x52, 0xe3, 0xe2, - 0x08, 0x4a, 0x2d, 0x2e, 0xc8, 0xcf, 0x2b, 0x4e, 0x15, 0x92, 0xe2, 0xe2, 0x28, 0x82, 0xb2, 0x25, - 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0xe0, 0xfc, 0x24, 0x36, 0xb0, 0x2e, 0x63, 0x40, 0x00, 0x00, - 0x00, 0xff, 0xff, 0xff, 0x0c, 0x67, 0x1e, 0x42, 0x00, 0x00, 0x00, +func init() { file_foo_proto_init() } +func file_foo_proto_init() { + if File_foo_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_foo_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Response); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_foo_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_foo_proto_goTypes, + DependencyIndexes: file_foo_proto_depIdxs, + MessageInfos: file_foo_proto_msgTypes, + }.Build() + File_foo_proto = out.File + file_foo_proto_rawDesc = nil + file_foo_proto_goTypes = nil + file_foo_proto_depIdxs = nil } diff --git a/example/multi-package/foo.proto b/example/multi-package/foo.proto index 44d1af19..8b60fd61 100644 --- a/example/multi-package/foo.proto +++ b/example/multi-package/foo.proto @@ -1,6 +1,10 @@ syntax = "proto3"; -package hello; +// simulating neighboring .proto file +// but different package +package foo; + +option go_package = "github.com/tokopedia/gripmock/example/multi-package"; message Response { string response = 1; diff --git a/example/multi-package/hello.pb.go b/example/multi-package/hello.pb.go index e7ff1755..88853ba8 100644 --- a/example/multi-package/hello.pb.go +++ b/example/multi-package/hello.pb.go @@ -1,36 +1,91 @@ // Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.17.3 // source: hello.proto -package hello - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" -import bar "github.com/tokopedia/gripmock/example/multi-package/bar" +package multi_package import ( - context "golang.org/x/net/context" + context "context" + bar "github.com/tokopedia/gripmock/example/multi-package/bar" grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" ) -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package +var File_hello_proto protoreflect.FileDescriptor + +var file_hello_proto_rawDesc = []byte{ + 0x0a, 0x0b, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0d, 0x6d, + 0x75, 0x6c, 0x74, 0x69, 0x5f, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x1a, 0x0d, 0x62, 0x61, + 0x72, 0x2f, 0x62, 0x61, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x09, 0x66, 0x6f, 0x6f, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0x2c, 0x0a, 0x08, 0x47, 0x72, 0x69, 0x70, 0x6d, 0x6f, + 0x63, 0x6b, 0x12, 0x20, 0x0a, 0x05, 0x47, 0x72, 0x65, 0x65, 0x74, 0x12, 0x08, 0x2e, 0x62, 0x61, + 0x72, 0x2e, 0x42, 0x61, 0x72, 0x1a, 0x0d, 0x2e, 0x66, 0x6f, 0x6f, 0x2e, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x35, 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x74, 0x6f, 0x6b, 0x6f, 0x70, 0x65, 0x64, 0x69, 0x61, 0x2f, 0x67, 0x72, 0x69, + 0x70, 0x6d, 0x6f, 0x63, 0x6b, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, 0x6d, 0x75, + 0x6c, 0x74, 0x69, 0x2d, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, +} + +var file_hello_proto_goTypes = []interface{}{ + (*bar.Bar)(nil), // 0: bar.Bar + (*Response)(nil), // 1: foo.Response +} +var file_hello_proto_depIdxs = []int32{ + 0, // 0: multi_package.Gripmock.Greet:input_type -> bar.Bar + 1, // 1: multi_package.Gripmock.Greet:output_type -> foo.Response + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_hello_proto_init() } +func file_hello_proto_init() { + if File_hello_proto != nil { + return + } + file_foo_proto_init() + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_hello_proto_rawDesc, + NumEnums: 0, + NumMessages: 0, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_hello_proto_goTypes, + DependencyIndexes: file_hello_proto_depIdxs, + }.Build() + File_hello_proto = out.File + file_hello_proto_rawDesc = nil + file_hello_proto_goTypes = nil + file_hello_proto_depIdxs = nil +} // Reference imports to suppress errors if they are not otherwise used. var _ context.Context -var _ grpc.ClientConn +var _ grpc.ClientConnInterface // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 +const _ = grpc.SupportPackageIsVersion6 // GripmockClient is the client API for Gripmock service. // @@ -40,16 +95,16 @@ type GripmockClient interface { } type gripmockClient struct { - cc *grpc.ClientConn + cc grpc.ClientConnInterface } -func NewGripmockClient(cc *grpc.ClientConn) GripmockClient { +func NewGripmockClient(cc grpc.ClientConnInterface) GripmockClient { return &gripmockClient{cc} } func (c *gripmockClient) Greet(ctx context.Context, in *bar.Bar, opts ...grpc.CallOption) (*Response, error) { out := new(Response) - err := c.cc.Invoke(ctx, "/hello.Gripmock/Greet", in, out, opts...) + err := c.cc.Invoke(ctx, "/multi_package.Gripmock/Greet", in, out, opts...) if err != nil { return nil, err } @@ -61,6 +116,14 @@ type GripmockServer interface { Greet(context.Context, *bar.Bar) (*Response, error) } +// UnimplementedGripmockServer can be embedded to have forward compatible implementations. +type UnimplementedGripmockServer struct { +} + +func (*UnimplementedGripmockServer) Greet(context.Context, *bar.Bar) (*Response, error) { + return nil, status.Errorf(codes.Unimplemented, "method Greet not implemented") +} + func RegisterGripmockServer(s *grpc.Server, srv GripmockServer) { s.RegisterService(&_Gripmock_serviceDesc, srv) } @@ -75,7 +138,7 @@ func _Gripmock_Greet_Handler(srv interface{}, ctx context.Context, dec func(inte } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/hello.Gripmock/Greet", + FullMethod: "/multi_package.Gripmock/Greet", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(GripmockServer).Greet(ctx, req.(*bar.Bar)) @@ -84,7 +147,7 @@ func _Gripmock_Greet_Handler(srv interface{}, ctx context.Context, dec func(inte } var _Gripmock_serviceDesc = grpc.ServiceDesc{ - ServiceName: "hello.Gripmock", + ServiceName: "multi_package.Gripmock", HandlerType: (*GripmockServer)(nil), Methods: []grpc.MethodDesc{ { @@ -95,16 +158,3 @@ var _Gripmock_serviceDesc = grpc.ServiceDesc{ Streams: []grpc.StreamDesc{}, Metadata: "hello.proto", } - -func init() { proto.RegisterFile("hello.proto", fileDescriptor_hello_86daf9ea719884b9) } - -var fileDescriptor_hello_86daf9ea719884b9 = []byte{ - // 105 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xce, 0x48, 0xcd, 0xc9, - 0xc9, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x05, 0x73, 0xa4, 0x78, 0x93, 0x12, 0x8b, - 0xf4, 0x93, 0x12, 0x8b, 0x20, 0xa2, 0x52, 0x9c, 0x69, 0xf9, 0x50, 0x05, 0x46, 0x7a, 0x5c, 0x1c, - 0xee, 0x45, 0x99, 0x05, 0xb9, 0xf9, 0xc9, 0xd9, 0x42, 0x4a, 0x5c, 0xac, 0xee, 0x45, 0xa9, 0xa9, - 0x25, 0x42, 0x1c, 0x7a, 0x20, 0xb5, 0x4e, 0x89, 0x45, 0x52, 0xfc, 0x7a, 0x10, 0xd3, 0x82, 0x52, - 0x8b, 0x0b, 0xf2, 0xf3, 0x8a, 0x53, 0x93, 0xd8, 0xc0, 0xda, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, - 0xff, 0xa4, 0x51, 0x1d, 0xb3, 0x66, 0x00, 0x00, 0x00, -} diff --git a/example/multi-package/hello.proto b/example/multi-package/hello.proto index 49e07a84..ffb12f9b 100644 --- a/example/multi-package/hello.proto +++ b/example/multi-package/hello.proto @@ -1,11 +1,14 @@ syntax = "proto3"; -package hello; +package multi_package; import "bar/bar.proto"; import "foo.proto"; +// simulate go_package alias with - +option go_package = "github.com/tokopedia/gripmock/example/multi-package"; + service Gripmock { - rpc Greet (bar.Bar) returns (Response); + rpc Greet (bar.Bar) returns (foo.Response); } diff --git a/example/one-of/client/main.go b/example/one-of/client/main.go index 9cb3e6cb..441a8502 100644 --- a/example/one-of/client/main.go +++ b/example/one-of/client/main.go @@ -11,6 +11,7 @@ import ( "google.golang.org/grpc" ) +//go:generate protoc --go_out=plugins=grpc:${GOPATH}/src -I=.. ../oneof.proto func main() { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() diff --git a/example/one-of/entrypoint.sh b/example/one-of/entrypoint.sh index 71418bf3..44eae91e 100755 --- a/example/one-of/entrypoint.sh +++ b/example/one-of/entrypoint.sh @@ -4,4 +4,7 @@ gripmock --stub=example/one-of/stub example/one-of/oneof.proto & +# wait for generated files to be available and gripmock is up +sleep 2 + go run example/one-of/client/*.go \ No newline at end of file diff --git a/example/one-of/oneof.pb.go b/example/one-of/oneof.pb.go index c086c330..95911457 100644 --- a/example/one-of/oneof.pb.go +++ b/example/one-of/oneof.pb.go @@ -1,14 +1,13 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.25.0 -// protoc v3.13.0 +// protoc-gen-go v1.27.1 +// protoc v3.17.3 // source: oneof.proto -package oneof +package one_of import ( context "context" - proto "github.com/golang/protobuf/proto" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -25,10 +24,6 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - // The request message containing the user's name. type Request struct { state protoimpl.MessageState @@ -283,7 +278,10 @@ var file_oneof_proto_rawDesc = []byte{ 0x32, 0x34, 0x0a, 0x08, 0x47, 0x72, 0x69, 0x70, 0x6d, 0x6f, 0x63, 0x6b, 0x12, 0x28, 0x0a, 0x08, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x0e, 0x2e, 0x6f, 0x6e, 0x65, 0x6f, 0x66, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0c, 0x2e, 0x6f, 0x6e, 0x65, 0x6f, 0x66, - 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x42, 0x2e, 0x5a, 0x2c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x74, 0x6f, 0x6b, 0x6f, 0x70, 0x65, 0x64, 0x69, 0x61, 0x2f, 0x67, + 0x72, 0x69, 0x70, 0x6d, 0x6f, 0x63, 0x6b, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, + 0x6f, 0x6e, 0x65, 0x2d, 0x6f, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/example/one-of/oneof.proto b/example/one-of/oneof.proto index 4042bbae..ca15d967 100644 --- a/example/one-of/oneof.proto +++ b/example/one-of/oneof.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package oneof; +option go_package = "github.com/tokopedia/gripmock/example/one-of"; + // The Gripmock service definition. service Gripmock { // simple unary method diff --git a/example/simple/client/main.go b/example/simple/client/main.go index 376083bf..b5e6a73e 100644 --- a/example/simple/client/main.go +++ b/example/simple/client/main.go @@ -10,6 +10,7 @@ import ( "google.golang.org/grpc" ) +//go:generate protoc -I=.. --go_out=plugins=grpc:${GOPATH}/src ../simple.proto func main() { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() diff --git a/example/simple/entrypoint.sh b/example/simple/entrypoint.sh index 120cc232..d9977069 100755 --- a/example/simple/entrypoint.sh +++ b/example/simple/entrypoint.sh @@ -4,4 +4,7 @@ gripmock --stub=example/simple/stub example/simple/simple.proto & +# wait for generated files to be available and gripmock is up +sleep 2 + go run example/simple/client/*.go \ No newline at end of file diff --git a/example/simple/simple.pb.go b/example/simple/simple.pb.go index 88827039..bdd2f784 100644 --- a/example/simple/simple.pb.go +++ b/example/simple/simple.pb.go @@ -1,14 +1,13 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.24.0-devel -// protoc v3.12.2 +// protoc-gen-go v1.27.1 +// protoc v3.17.3 // source: simple.proto package simple import ( context "context" - proto "github.com/golang/protobuf/proto" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -25,10 +24,6 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - // The request message containing the user's name. type Request struct { state protoimpl.MessageState @@ -147,7 +142,10 @@ var file_simple_proto_rawDesc = []byte{ 0x70, 0x6d, 0x6f, 0x63, 0x6b, 0x12, 0x2a, 0x0a, 0x08, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x0f, 0x2e, 0x73, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x73, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x52, 0x65, 0x70, 0x6c, - 0x79, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x79, 0x42, 0x2e, 0x5a, 0x2c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x74, 0x6f, 0x6b, 0x6f, 0x70, 0x65, 0x64, 0x69, 0x61, 0x2f, 0x67, 0x72, 0x69, 0x70, 0x6d, 0x6f, + 0x63, 0x6b, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, 0x73, 0x69, 0x6d, 0x70, 0x6c, + 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/example/simple/simple.proto b/example/simple/simple.proto index 92392178..f1cc994c 100644 --- a/example/simple/simple.proto +++ b/example/simple/simple.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package simple; +option go_package = "github.com/tokopedia/gripmock/example/simple"; + // The Gripmock service definition. service Gripmock { // simple unary method diff --git a/example/stream/client/main.go b/example/stream/client/main.go index d94d7233..01ad610f 100644 --- a/example/stream/client/main.go +++ b/example/stream/client/main.go @@ -11,6 +11,7 @@ import ( "google.golang.org/grpc" ) +//go:generate protoc --go_out=plugins=grpc:${GOPATH}/src -I=.. ../stream.proto func main() { // Set up a connection to the server. ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) diff --git a/example/stream/entrypoint.sh b/example/stream/entrypoint.sh index 886aab5d..e4e180e3 100755 --- a/example/stream/entrypoint.sh +++ b/example/stream/entrypoint.sh @@ -4,4 +4,7 @@ gripmock --stub=example/stream/stub example/stream/stream.proto & +# wait for generated files to be available and gripmock is up +sleep 2 + go run example/stream/client/*.go \ No newline at end of file diff --git a/example/stream/stream.pb.go b/example/stream/stream.pb.go index 57d7a7b9..0901edb8 100644 --- a/example/stream/stream.pb.go +++ b/example/stream/stream.pb.go @@ -1,118 +1,239 @@ // Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.17.3 // source: stream.proto package stream -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" - import ( - context "golang.org/x/net/context" + context "context" grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" ) -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) // The request message containing the user's name. type Request struct { - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -func (m *Request) Reset() { *m = Request{} } -func (m *Request) String() string { return proto.CompactTextString(m) } -func (*Request) ProtoMessage() {} -func (*Request) Descriptor() ([]byte, []int) { - return fileDescriptor_stream_b89e769b981cf265, []int{0} -} -func (m *Request) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Request.Unmarshal(m, b) -} -func (m *Request) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Request.Marshal(b, m, deterministic) + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` } -func (dst *Request) XXX_Merge(src proto.Message) { - xxx_messageInfo_Request.Merge(dst, src) + +func (x *Request) Reset() { + *x = Request{} + if protoimpl.UnsafeEnabled { + mi := &file_stream_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } -func (m *Request) XXX_Size() int { - return xxx_messageInfo_Request.Size(m) + +func (x *Request) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *Request) XXX_DiscardUnknown() { - xxx_messageInfo_Request.DiscardUnknown(m) + +func (*Request) ProtoMessage() {} + +func (x *Request) ProtoReflect() protoreflect.Message { + mi := &file_stream_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -var xxx_messageInfo_Request proto.InternalMessageInfo +// Deprecated: Use Request.ProtoReflect.Descriptor instead. +func (*Request) Descriptor() ([]byte, []int) { + return file_stream_proto_rawDescGZIP(), []int{0} +} -func (m *Request) GetName() string { - if m != nil { - return m.Name +func (x *Request) GetName() string { + if x != nil { + return x.Name } return "" } // The response message containing the greetings type Reply struct { - Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -func (m *Reply) Reset() { *m = Reply{} } -func (m *Reply) String() string { return proto.CompactTextString(m) } -func (*Reply) ProtoMessage() {} -func (*Reply) Descriptor() ([]byte, []int) { - return fileDescriptor_stream_b89e769b981cf265, []int{1} -} -func (m *Reply) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Reply.Unmarshal(m, b) -} -func (m *Reply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Reply.Marshal(b, m, deterministic) + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` } -func (dst *Reply) XXX_Merge(src proto.Message) { - xxx_messageInfo_Reply.Merge(dst, src) + +func (x *Reply) Reset() { + *x = Reply{} + if protoimpl.UnsafeEnabled { + mi := &file_stream_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } -func (m *Reply) XXX_Size() int { - return xxx_messageInfo_Reply.Size(m) + +func (x *Reply) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *Reply) XXX_DiscardUnknown() { - xxx_messageInfo_Reply.DiscardUnknown(m) + +func (*Reply) ProtoMessage() {} + +func (x *Reply) ProtoReflect() protoreflect.Message { + mi := &file_stream_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -var xxx_messageInfo_Reply proto.InternalMessageInfo +// Deprecated: Use Reply.ProtoReflect.Descriptor instead. +func (*Reply) Descriptor() ([]byte, []int) { + return file_stream_proto_rawDescGZIP(), []int{1} +} -func (m *Reply) GetMessage() string { - if m != nil { - return m.Message +func (x *Reply) GetMessage() string { + if x != nil { + return x.Message } return "" } -func init() { - proto.RegisterType((*Request)(nil), "stream.Request") - proto.RegisterType((*Reply)(nil), "stream.Reply") +var File_stream_proto protoreflect.FileDescriptor + +var file_stream_proto_rawDesc = []byte{ + 0x0a, 0x0c, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, + 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x22, 0x1d, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x21, 0x0a, 0x05, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x18, + 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0xa3, 0x01, 0x0a, 0x08, 0x47, 0x72, 0x69, + 0x70, 0x6d, 0x6f, 0x63, 0x6b, 0x12, 0x30, 0x0a, 0x0c, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x53, + 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x0f, 0x2e, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2e, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2e, + 0x52, 0x65, 0x70, 0x6c, 0x79, 0x30, 0x01, 0x12, 0x30, 0x0a, 0x0c, 0x63, 0x6c, 0x69, 0x65, 0x6e, + 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x0f, 0x2e, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, + 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x73, 0x74, 0x72, 0x65, 0x61, + 0x6d, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x28, 0x01, 0x12, 0x33, 0x0a, 0x0d, 0x62, 0x69, 0x64, + 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x12, 0x0f, 0x2e, 0x73, 0x74, 0x72, + 0x65, 0x61, 0x6d, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x73, 0x74, + 0x72, 0x65, 0x61, 0x6d, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x28, 0x01, 0x30, 0x01, 0x42, 0x2e, + 0x5a, 0x2c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x74, 0x6f, 0x6b, + 0x6f, 0x70, 0x65, 0x64, 0x69, 0x61, 0x2f, 0x67, 0x72, 0x69, 0x70, 0x6d, 0x6f, 0x63, 0x6b, 0x2f, + 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_stream_proto_rawDescOnce sync.Once + file_stream_proto_rawDescData = file_stream_proto_rawDesc +) + +func file_stream_proto_rawDescGZIP() []byte { + file_stream_proto_rawDescOnce.Do(func() { + file_stream_proto_rawDescData = protoimpl.X.CompressGZIP(file_stream_proto_rawDescData) + }) + return file_stream_proto_rawDescData +} + +var file_stream_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_stream_proto_goTypes = []interface{}{ + (*Request)(nil), // 0: stream.Request + (*Reply)(nil), // 1: stream.Reply +} +var file_stream_proto_depIdxs = []int32{ + 0, // 0: stream.Gripmock.serverStream:input_type -> stream.Request + 0, // 1: stream.Gripmock.clientStream:input_type -> stream.Request + 0, // 2: stream.Gripmock.bidirectional:input_type -> stream.Request + 1, // 3: stream.Gripmock.serverStream:output_type -> stream.Reply + 1, // 4: stream.Gripmock.clientStream:output_type -> stream.Reply + 1, // 5: stream.Gripmock.bidirectional:output_type -> stream.Reply + 3, // [3:6] is the sub-list for method output_type + 0, // [0:3] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_stream_proto_init() } +func file_stream_proto_init() { + if File_stream_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_stream_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Request); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_stream_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Reply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_stream_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_stream_proto_goTypes, + DependencyIndexes: file_stream_proto_depIdxs, + MessageInfos: file_stream_proto_msgTypes, + }.Build() + File_stream_proto = out.File + file_stream_proto_rawDesc = nil + file_stream_proto_goTypes = nil + file_stream_proto_depIdxs = nil } // Reference imports to suppress errors if they are not otherwise used. var _ context.Context -var _ grpc.ClientConn +var _ grpc.ClientConnInterface // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 +const _ = grpc.SupportPackageIsVersion6 // GripmockClient is the client API for Gripmock service. // @@ -127,10 +248,10 @@ type GripmockClient interface { } type gripmockClient struct { - cc *grpc.ClientConn + cc grpc.ClientConnInterface } -func NewGripmockClient(cc *grpc.ClientConn) GripmockClient { +func NewGripmockClient(cc grpc.ClientConnInterface) GripmockClient { return &gripmockClient{cc} } @@ -241,6 +362,20 @@ type GripmockServer interface { Bidirectional(Gripmock_BidirectionalServer) error } +// UnimplementedGripmockServer can be embedded to have forward compatible implementations. +type UnimplementedGripmockServer struct { +} + +func (*UnimplementedGripmockServer) ServerStream(*Request, Gripmock_ServerStreamServer) error { + return status.Errorf(codes.Unimplemented, "method ServerStream not implemented") +} +func (*UnimplementedGripmockServer) ClientStream(Gripmock_ClientStreamServer) error { + return status.Errorf(codes.Unimplemented, "method ClientStream not implemented") +} +func (*UnimplementedGripmockServer) Bidirectional(Gripmock_BidirectionalServer) error { + return status.Errorf(codes.Unimplemented, "method Bidirectional not implemented") +} + func RegisterGripmockServer(s *grpc.Server, srv GripmockServer) { s.RegisterService(&_Gripmock_serviceDesc, srv) } @@ -342,20 +477,3 @@ var _Gripmock_serviceDesc = grpc.ServiceDesc{ }, Metadata: "stream.proto", } - -func init() { proto.RegisterFile("stream.proto", fileDescriptor_stream_b89e769b981cf265) } - -var fileDescriptor_stream_b89e769b981cf265 = []byte{ - // 173 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x29, 0x2e, 0x29, 0x4a, - 0x4d, 0xcc, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0xf0, 0x94, 0x64, 0xb9, 0xd8, - 0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x84, 0x84, 0xb8, 0x58, 0xf2, 0x12, 0x73, 0x53, 0x25, - 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0xc0, 0x6c, 0x25, 0x45, 0x2e, 0xd6, 0xa0, 0xd4, 0x82, 0x9c, - 0x4a, 0x21, 0x09, 0x2e, 0xf6, 0xdc, 0xd4, 0xe2, 0xe2, 0xc4, 0x74, 0x98, 0x3c, 0x8c, 0x6b, 0xb4, - 0x98, 0x91, 0x8b, 0xc3, 0xbd, 0x28, 0xb3, 0x20, 0x37, 0x3f, 0x39, 0x5b, 0xc8, 0x80, 0x8b, 0xa7, - 0x38, 0xb5, 0xa8, 0x2c, 0xb5, 0x28, 0x18, 0x6c, 0xbc, 0x10, 0xbf, 0x1e, 0xd4, 0x56, 0xa8, 0x25, - 0x52, 0xbc, 0x08, 0x81, 0x82, 0x9c, 0x4a, 0x03, 0x46, 0x90, 0x8e, 0xe4, 0x9c, 0xcc, 0xd4, 0xbc, - 0x12, 0xe2, 0x74, 0x68, 0x30, 0x0a, 0x19, 0x73, 0xf1, 0x26, 0x65, 0xa6, 0x64, 0x16, 0xa5, 0x26, - 0x97, 0x64, 0xe6, 0xe7, 0x25, 0xe6, 0x10, 0xd6, 0x62, 0xc0, 0x98, 0xc4, 0x06, 0xf6, 0xb6, 0x31, - 0x20, 0x00, 0x00, 0xff, 0xff, 0x62, 0x90, 0x1d, 0x75, 0x06, 0x01, 0x00, 0x00, -} diff --git a/example/stream/stream.proto b/example/stream/stream.proto index 502ab571..a1c10f13 100644 --- a/example/stream/stream.proto +++ b/example/stream/stream.proto @@ -2,6 +2,7 @@ syntax = "proto3"; package stream; +option go_package = "github.com/tokopedia/gripmock/example/stream"; // The Gripmock service definition. service Gripmock { // server to client sreaming diff --git a/example/well_known_types/client/main.go b/example/well_known_types/client/main.go index f26fec55..3b0aaba2 100644 --- a/example/well_known_types/client/main.go +++ b/example/well_known_types/client/main.go @@ -10,6 +10,9 @@ import ( "google.golang.org/grpc" ) +// in order to generate this .pb.go you need to have https://github.com/google/protobuf.git cloned +// then use it as protobuf_dir below +// protoc --go_out=plugins=grpc:${GOPATH}/src -I=.. -I= ../wkt.proto func main() { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() diff --git a/example/well_known_types/entrypoint.sh b/example/well_known_types/entrypoint.sh index 9c656083..bfe10827 100755 --- a/example/well_known_types/entrypoint.sh +++ b/example/well_known_types/entrypoint.sh @@ -4,4 +4,7 @@ gripmock --stub=example/well_known_types/stub example/well_known_types/wkt.proto & +# wait for generated files to be available and gripmock is up +sleep 2 + go run example/well_known_types/client/*.go \ No newline at end of file diff --git a/example/well_known_types/wkt.pb.go b/example/well_known_types/wkt.pb.go index 215acf97..13877f7d 100644 --- a/example/well_known_types/wkt.pb.go +++ b/example/well_known_types/wkt.pb.go @@ -1,50 +1,110 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: well_known_types/well_known_types.proto +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.17.3 +// source: wkt.proto -package well_known_types - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" -import empty "github.com/golang/protobuf/ptypes/empty" -import api "google.golang.org/genproto/protobuf/api" +package wkt import ( - context "golang.org/x/net/context" + context "context" + empty "github.com/golang/protobuf/ptypes/empty" + api "google.golang.org/genproto/protobuf/api" grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" ) -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package +var File_wkt_proto protoreflect.FileDescriptor + +var file_wkt_proto_rawDesc = []byte{ + 0x0a, 0x09, 0x77, 0x6b, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x10, 0x77, 0x65, 0x6c, + 0x6c, 0x5f, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x1a, 0x1b, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, + 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x19, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x61, 0x70, 0x69, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0x43, 0x0a, 0x08, 0x47, 0x72, 0x69, 0x70, 0x6d, 0x6f, 0x63, + 0x6b, 0x12, 0x37, 0x0a, 0x07, 0x41, 0x70, 0x69, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x16, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, + 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x41, 0x70, 0x69, 0x42, 0x3c, 0x5a, 0x3a, 0x67, 0x69, + 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x74, 0x6f, 0x6b, 0x6f, 0x70, 0x65, 0x64, + 0x69, 0x61, 0x2f, 0x67, 0x72, 0x69, 0x70, 0x6d, 0x6f, 0x63, 0x6b, 0x2f, 0x65, 0x78, 0x61, 0x6d, + 0x70, 0x6c, 0x65, 0x2f, 0x77, 0x65, 0x6c, 0x6c, 0x5f, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x5f, 0x74, + 0x79, 0x70, 0x65, 0x73, 0x3b, 0x77, 0x6b, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var file_wkt_proto_goTypes = []interface{}{ + (*empty.Empty)(nil), // 0: google.protobuf.Empty + (*api.Api)(nil), // 1: google.protobuf.Api +} +var file_wkt_proto_depIdxs = []int32{ + 0, // 0: well_known_types.Gripmock.ApiInfo:input_type -> google.protobuf.Empty + 1, // 1: well_known_types.Gripmock.ApiInfo:output_type -> google.protobuf.Api + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_wkt_proto_init() } +func file_wkt_proto_init() { + if File_wkt_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_wkt_proto_rawDesc, + NumEnums: 0, + NumMessages: 0, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_wkt_proto_goTypes, + DependencyIndexes: file_wkt_proto_depIdxs, + }.Build() + File_wkt_proto = out.File + file_wkt_proto_rawDesc = nil + file_wkt_proto_goTypes = nil + file_wkt_proto_depIdxs = nil +} // Reference imports to suppress errors if they are not otherwise used. var _ context.Context -var _ grpc.ClientConn +var _ grpc.ClientConnInterface // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 +const _ = grpc.SupportPackageIsVersion6 // GripmockClient is the client API for Gripmock service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type GripmockClient interface { + // this shows us example on using WKT as dependency + // api.proto in particular has go_package alias with semicolon + // "google.golang.org/genproto/protobuf/api;api" ApiInfo(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*api.Api, error) } type gripmockClient struct { - cc *grpc.ClientConn + cc grpc.ClientConnInterface } -func NewGripmockClient(cc *grpc.ClientConn) GripmockClient { +func NewGripmockClient(cc grpc.ClientConnInterface) GripmockClient { return &gripmockClient{cc} } @@ -59,9 +119,20 @@ func (c *gripmockClient) ApiInfo(ctx context.Context, in *empty.Empty, opts ...g // GripmockServer is the server API for Gripmock service. type GripmockServer interface { + // this shows us example on using WKT as dependency + // api.proto in particular has go_package alias with semicolon + // "google.golang.org/genproto/protobuf/api;api" ApiInfo(context.Context, *empty.Empty) (*api.Api, error) } +// UnimplementedGripmockServer can be embedded to have forward compatible implementations. +type UnimplementedGripmockServer struct { +} + +func (*UnimplementedGripmockServer) ApiInfo(context.Context, *empty.Empty) (*api.Api, error) { + return nil, status.Errorf(codes.Unimplemented, "method ApiInfo not implemented") +} + func RegisterGripmockServer(s *grpc.Server, srv GripmockServer) { s.RegisterService(&_Gripmock_serviceDesc, srv) } @@ -94,22 +165,5 @@ var _Gripmock_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "well_known_types/well_known_types.proto", -} - -func init() { - proto.RegisterFile("well_known_types/well_known_types.proto", fileDescriptor_well_known_types_79f0e9b76c3d9f98) -} - -var fileDescriptor_well_known_types_79f0e9b76c3d9f98 = []byte{ - // 133 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x2f, 0x4f, 0xcd, 0xc9, - 0x89, 0xcf, 0xce, 0xcb, 0x2f, 0xcf, 0x8b, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0xd6, 0x47, 0x17, 0xd0, - 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x40, 0x17, 0x97, 0x92, 0x4e, 0xcf, 0xcf, 0x4f, 0xcf, - 0x49, 0xd5, 0x07, 0xcb, 0x27, 0x95, 0xa6, 0xe9, 0xa7, 0xe6, 0x16, 0x94, 0x54, 0x42, 0x94, 0x4b, - 0x49, 0xa2, 0x4b, 0x26, 0x16, 0x64, 0x42, 0xa4, 0x8c, 0x9c, 0xb9, 0x38, 0xdc, 0x8b, 0x32, 0x0b, - 0x72, 0xf3, 0x93, 0xb3, 0x85, 0xcc, 0xb9, 0xd8, 0x1d, 0x0b, 0x32, 0x3d, 0xf3, 0xd2, 0xf2, 0x85, - 0xc4, 0xf4, 0x20, 0x5a, 0xf4, 0x60, 0x5a, 0xf4, 0x5c, 0x41, 0xe6, 0x49, 0x89, 0x60, 0x88, 0x3b, - 0x16, 0x64, 0x26, 0xb1, 0x81, 0x79, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x4e, 0x55, 0xb9, - 0x1e, 0xc0, 0x00, 0x00, 0x00, + Metadata: "wkt.proto", } diff --git a/example/well_known_types/wkt.proto b/example/well_known_types/wkt.proto index 9c5ccce0..9884d959 100644 --- a/example/well_known_types/wkt.proto +++ b/example/well_known_types/wkt.proto @@ -5,6 +5,7 @@ package well_known_types; import "google/protobuf/empty.proto"; import "google/protobuf/api.proto"; +option go_package = "github.com/tokopedia/gripmock/example/well_known_types;wkt"; service Gripmock { // this shows us example on using WKT as dependency // api.proto in particular has go_package alias with semicolon diff --git a/go.mod b/go.mod index 973d64b4..fe5653eb 100644 --- a/go.mod +++ b/go.mod @@ -3,18 +3,19 @@ module github.com/tokopedia/gripmock go 1.15 require ( + github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-chi/chi v4.1.2+incompatible - github.com/gobuffalo/here v0.6.2 // indirect - github.com/golang/protobuf v1.4.3 + github.com/golang/protobuf v1.5.2 + github.com/kr/pretty v0.2.0 // indirect github.com/lithammer/fuzzysearch v1.1.1 - github.com/markbates/pkger v0.17.1 github.com/stretchr/testify v1.6.1 - golang.org/x/net v0.0.0-20201110031124-69a78807bb2b + golang.org/x/net v0.0.0-20201110031124-69a78807bb2b // indirect golang.org/x/sys v0.0.0-20201112073958-5cba982894dd // indirect golang.org/x/text v0.3.4 // indirect - golang.org/x/tools v0.0.0-20201111224557-41a3a589386c + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect google.golang.org/genproto v0.0.0-20201111145450-ac7456db90a6 google.golang.org/grpc v1.33.2 - google.golang.org/protobuf v1.25.0 + google.golang.org/protobuf v1.27.1 + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect ) diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..7f4a09da --- /dev/null +++ b/go.sum @@ -0,0 +1,119 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/go-chi/chi v4.1.2+incompatible h1:fGFk2Gmi/YKXk0OmGfBh0WgmN3XB8lVnEyNz34tQRec= +github.com/go-chi/chi v4.1.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= +github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/lithammer/fuzzysearch v1.1.1 h1:8F9OAV2xPuYblToVohjanztdnPjbtA0MLgMvDKQ0Z08= +github.com/lithammer/fuzzysearch v1.1.1/go.mod h1:H2bng+w5gsR7NlfIJM8ElGZI0sX6C/9uzGqicVXGU6c= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME= +golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201112073958-5cba982894dd h1:5CtCZbICpIOFdgO940moixOPjc0178IU44m4EjOO5IY= +golang.org/x/sys v0.0.0-20201112073958-5cba982894dd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc= +golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 h1:5Beo0mZN8dRzgrMMkDp0jc8YXQKx9DiJ2k1dkvGsn5A= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20201111145450-ac7456db90a6 h1:iRN4+t0lvZX/l9gH14ARF9i58tsVa5a97k6aH95rC3Y= +google.golang.org/genproto v0.0.0-20201111145450-ac7456db90a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o= +google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/gripmock.go b/gripmock.go index d3570a03..18a05f4a 100644 --- a/gripmock.go +++ b/gripmock.go @@ -28,12 +28,11 @@ func main() { flag.Parse() fmt.Println("Starting GripMock") - + if os.Getenv("GOPATH") == "" { + log.Fatal("$GOPATH is empty") + } output := *outputPointer if output == "" { - if os.Getenv("GOPATH") == "" { - log.Fatal("output is not provided and GOPATH is empty") - } output = os.Getenv("GOPATH") + "/src/grpc" } @@ -70,7 +69,7 @@ func main() { }) // build the server - buildServer(output, protoPaths) + //buildServer(output) // and run run, runerr := runGrpcServer(output) @@ -113,8 +112,12 @@ func generateProtoc(param protocParam) { for _, i := range param.imports { args = append(args, "-I", i) } + + // the latest go-grpc plugin will generate subfolders under $GOPATH/src based on go_package option + pbOutput := os.Getenv("GOPATH") + "/src" + args = append(args, param.protoPath...) - args = append(args, "--go_out=plugins=grpc:"+param.output) + args = append(args, "--go_out=plugins=grpc:"+pbOutput) args = append(args, fmt.Sprintf("--gripmock_out=admin-port=%s,grpc-address=%s,grpc-port=%s:%s", param.adminPort, param.grpcAddress, param.grpcPort, param.output)) protoc := exec.Command("protoc", args...) @@ -125,24 +128,11 @@ func generateProtoc(param protocParam) { log.Fatal("Fail on protoc ", err) } - // change package to "main" on generated code - for _, proto := range param.protoPath { - protoname := getProtoName(proto) - sed := exec.Command("sed", "-i", `s/^package \w*$/package main/`, param.output+protoname+".pb.go") - sed.Stderr = os.Stderr - sed.Stdout = os.Stdout - err = sed.Run() - if err != nil { - log.Fatal("Fail on sed") - } - } } -func buildServer(output string, protoPaths []string) { - args := []string{"build", "-o", output + "grpcserver", output + "server.go"} - for _, path := range protoPaths { - args = append(args, output+getProtoName(path)+".pb.go") - } +func buildServer(output string) { + args := []string{"build", "-o", output + "grpcserver", output} + build := exec.Command("go", args...) build.Stdout = os.Stdout build.Stderr = os.Stderr @@ -153,7 +143,7 @@ func buildServer(output string, protoPaths []string) { } func runGrpcServer(output string) (*exec.Cmd, <-chan error) { - run := exec.Command(output + "grpcserver") + run := exec.Command("go", "run", output+"server.go") run.Stdout = os.Stdout run.Stderr = os.Stderr err := run.Start() diff --git a/protoc-gen-gripmock/generator.go b/protoc-gen-gripmock/generator.go index 6f523ec6..cdd22584 100644 --- a/protoc-gen-gripmock/generator.go +++ b/protoc-gen-gripmock/generator.go @@ -83,10 +83,12 @@ type generatorParam struct { type Service struct { Name string + Package string Methods []methodTemplate } type methodTemplate struct { + SvcPackage string Name string ServiceName string MethodType string @@ -114,7 +116,7 @@ type Options struct { var SERVER_TEMPLATE string func init() { - f, err := pkger.Open("/protoc-gen-gripmock/server.tmpl") + f, err := pkger.Open("/server.tmpl") if err != nil { log.Fatalf("error opening server.tmpl: %s", err) } @@ -170,38 +172,30 @@ func generateServer(protos []*descriptor.FileDescriptorProto, opt *Options) erro } func resolveDependencies(protos []*descriptor.FileDescriptorProto) map[string]string { - depsFile := []string{} - for _, proto := range protos { - depsFile = append(depsFile, proto.GetDependency()...) - } deps := map[string]string{} - aliases := map[string]bool{} - aliasNum := 1 - for _, dep := range depsFile { - for _, proto := range protos { - alias, pkg := getGoPackage(proto) - - // skip whether its not intended deps - // or has empty Go package - if proto.GetName() != dep || pkg == "" { - continue - } + for _, proto := range protos { + alias, pkg := getGoPackage(proto) - // in case of found same alias - if ok := aliases[alias]; ok { - alias = fmt.Sprintf("%s%d", alias, aliasNum) - aliasNum++ - } else { - aliases[alias] = true - } - deps[pkg] = alias + // fatal if go_package is not present + if pkg == "" { + log.Fatalf("option go_package is required. but %s doesn't have any", proto.GetName()) } + + if _, ok := deps[pkg]; ok { + continue + } + + deps[pkg] = alias } return deps } +var aliases = map[string]bool{} +var aliasNum = 1 +var packages = map[string]string{} + func getGoPackage(proto *descriptor.FileDescriptorProto) (alias string, goPackage string) { goPackage = proto.GetOptions().GetGoPackage() if goPackage == "" { @@ -214,9 +208,16 @@ func getGoPackage(proto *descriptor.FileDescriptorProto) (alias string, goPackag goPackage = splits[0] alias = splits[1] } else { - splitSlash := strings.Split(proto.GetName(), "/") - split := strings.Split(splitSlash[len(splitSlash)-1], ".") - alias = split[0] + // get the alias based on the latest folder + splitSlash := strings.Split(goPackage, "/") + // replace - with _ + alias = strings.ReplaceAll(splitSlash[len(splitSlash)-1], "-", "_") + } + + // if package already discovered just return + if al, ok := packages[goPackage]; ok { + alias = al + return } // Aliases can't be keywords @@ -224,6 +225,16 @@ func getGoPackage(proto *descriptor.FileDescriptorProto) (alias string, goPackag alias = fmt.Sprintf("%s_pb", alias) } + // in case of found same alias + // add numbers on it + if ok := aliases[alias]; ok { + alias = fmt.Sprintf("%s%d", alias, aliasNum) + aliasNum++ + } + + packages[goPackage] = alias + aliases[alias] = true + return } @@ -234,6 +245,10 @@ func extractServices(protos []*descriptor.FileDescriptorProto) []Service { for _, svc := range proto.GetService() { var s Service s.Name = svc.GetName() + alias, _ := getGoPackage(proto) + if alias != "" { + s.Package = alias + "." + } methods := make([]methodTemplate, len(svc.Method)) for j, method := range svc.Method { tipe := methodTypeStandard @@ -247,9 +262,10 @@ func extractServices(protos []*descriptor.FileDescriptorProto) []Service { methods[j] = methodTemplate{ Name: strings.Title(*method.Name), + SvcPackage: s.Package, ServiceName: svc.GetName(), - Input: getMessageType(protos, proto.GetDependency(), method.GetInputType()), - Output: getMessageType(protos, proto.GetDependency(), method.GetOutputType()), + Input: getMessageType(protos, method.GetInputType()), + Output: getMessageType(protos, method.GetOutputType()), MethodType: tipe, } } @@ -260,24 +276,22 @@ func extractServices(protos []*descriptor.FileDescriptorProto) []Service { return svcTmp } -func getMessageType(protos []*descriptor.FileDescriptorProto, deps []string, tipe string) string { +func getMessageType(protos []*descriptor.FileDescriptorProto, tipe string) string { split := strings.Split(tipe, ".")[1:] targetPackage := strings.Join(split[:len(split)-1], ".") targetType := split[len(split)-1] - for _, dep := range deps { - for _, proto := range protos { - if proto.GetName() != dep || proto.GetPackage() != targetPackage { - continue - } + for _, proto := range protos { + if proto.GetPackage() != targetPackage { + continue + } - for _, msg := range proto.GetMessageType() { - if msg.GetName() == targetType { - alias, _ := getGoPackage(proto) - if alias != "" { - alias += "." - } - return fmt.Sprintf("%s%s", alias, msg.GetName()) + for _, msg := range proto.GetMessageType() { + if msg.GetName() == targetType { + alias, _ := getGoPackage(proto) + if alias != "" { + alias += "." } + return fmt.Sprintf("%s%s", alias, msg.GetName()) } } } diff --git a/protoc-gen-gripmock/go.mod b/protoc-gen-gripmock/go.mod new file mode 100644 index 00000000..572f2a57 --- /dev/null +++ b/protoc-gen-gripmock/go.mod @@ -0,0 +1,10 @@ +module github.com/tokopedia/gripmock/protoc-gen-gripmock + +go 1.13 + +require ( + github.com/golang/protobuf v1.5.2 + github.com/markbates/pkger v0.17.1 + golang.org/x/tools v0.1.5 + google.golang.org/protobuf v1.27.1 +) diff --git a/protoc-gen-gripmock/go.sum b/protoc-gen-gripmock/go.sum new file mode 100644 index 00000000..574dc395 --- /dev/null +++ b/protoc-gen-gripmock/go.sum @@ -0,0 +1,44 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gobuffalo/here v0.6.0/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PLa8Y5fM= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/markbates/pkger v0.17.1/go.mod h1:0JoVlrol20BSywW79rN3kdFFsE5xYM+rSCQDXbLhiuI= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/protoc-gen-gripmock/server.tmpl b/protoc-gen-gripmock/server.tmpl index 4cd75e68..13531f71 100644 --- a/protoc-gen-gripmock/server.tmpl +++ b/protoc-gen-gripmock/server.tmpl @@ -78,24 +78,24 @@ func (s *{{.ServiceName}}) {{.Name}}(ctx context.Context, in *{{.Input}}) (*{{.O {{ end }} {{ define "server_stream_method" }} -func (s *{{.ServiceName}}) {{.Name}}(in *{{.Input}},stream {{.ServiceName}}_{{.Name}}Server) error { +func (s *{{.ServiceName}}) {{.Name}}(in *{{.Input}},srv {{.SvcPackage}}{{.ServiceName}}_{{.Name}}Server) error { out := &{{.Output}}{} err := findStub("{{.ServiceName}}", "{{.Name}}", in, out) if err!=nil { return err } - return stream.Send(out) + return srv.Send(out) } {{ end }} {{ define "client_stream_method"}} -func (s *{{.ServiceName}}) {{.Name}}(stream {{.ServiceName}}_{{.Name}}Server) error { +func (s *{{.ServiceName}}) {{.Name}}(srv {{.SvcPackage}}{{.ServiceName}}_{{.Name}}Server) error { out := &{{.Output}}{} for { - input,err := stream.Recv() + input,err := srv.Recv() if err == io.EOF { - return stream.SendAndClose(out) + return srv.SendAndClose(out) } err = findStub("{{.ServiceName}}","{{.Name}}",input,out) if err != nil { @@ -106,9 +106,9 @@ func (s *{{.ServiceName}}) {{.Name}}(stream {{.ServiceName}}_{{.Name}}Server) er {{ end }} {{ define "bidirectional_method"}} -func (s *{{.ServiceName}}) {{.Name}}(stream {{.ServiceName}}_{{.Name}}Server) error { +func (s *{{.ServiceName}}) {{.Name}}(srv {{.SvcPackage}}{{.ServiceName}}_{{.Name}}Server) error { for { - in, err := stream.Recv() + in, err := srv.Recv() if err == io.EOF { return nil } @@ -122,7 +122,7 @@ func (s *{{.ServiceName}}) {{.Name}}(stream {{.ServiceName}}_{{.Name}}Server) er return err } - if err := stream.Send(out); err != nil{ + if err := srv.Send(out); err != nil{ return err } } @@ -131,7 +131,7 @@ func (s *{{.ServiceName}}) {{.Name}}(stream {{.ServiceName}}_{{.Name}}Server) er {{ define "register_services" }} - Register{{.Name}}Server(s, &{{.Name}}{}) + {{.Package}}Register{{.Name}}Server(s, &{{.Name}}{}) {{ end }} {{ define "find_stub" }}