update tests and deps

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-07-05 16:26:57 +03:00
parent 3ceff22f52
commit 32039b342f
17 changed files with 826 additions and 105 deletions

60
client/drpc/drpc_test.go Normal file
View File

@@ -0,0 +1,60 @@
// +build ignore
/*
package drpc
import (
"context"
"net"
"testing"
drpc "github.com/unistack-org/micro-client-drpc/v3"
protocodec "github.com/unistack-org/micro-codec-proto/v3"
pb "github.com/unistack-org/micro-tests/client/drpc/proto"
"github.com/unistack-org/micro/v3/client"
"storj.io/drpc/drpcmux"
"storj.io/drpc/drpcserver"
)
type TestServer struct{}
func (s *TestServer) Call(ctx context.Context, req *pb.CallReq) (*pb.CallRsp, error) {
return &pb.CallRsp{Name: req.Name + " rsp"}, nil
}
func (s *TestServer) Hello(ctx context.Context, req *pb.CallReq) (*pb.CallRsp, error) {
return &pb.CallRsp{Name: req.Name + " rsp"}, nil
}
func TestDrpc(t *testing.T) {
t.Skip()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
m := drpcmux.New()
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
defer ln.Close()
err = pb.DRPCRegisterTestService(m, &TestServer{})
if err != nil {
t.Fatal(err)
}
go func() {
if err := drpcserver.New(m).Serve(ctx, ln); err != nil {
t.Fatal(err)
}
}()
c := client.NewClientCallOptions(drpc.NewClient(client.Codec("application/drpc+proto", protocodec.NewCodec())), client.WithAddress(ln.Addr().String()))
cli := pb.NewTestServiceClient("test", c)
rsp, err := cli.Call(ctx, &pb.CallReq{Name: "test_name"})
if err != nil {
t.Fatal(err)
}
if rsp.Name != "test_name rsp" {
t.Fatalf("unexpected rsp %#+v", rsp)
}
}
*/

5
client/drpc/generate.go Normal file
View File

@@ -0,0 +1,5 @@
package drpc
//xxgo:generate protoc -I./proto -I. --go_out=paths=source_relative:./proto --go-micro_out=components=micro|rpc,debug=true,paths=source_relative:./proto proto/test.proto
//go:generate protoc -I./proto -I. --go_out=paths=source_relative:./proto --go-micro_out=components=micro|rpc,debug=true,paths=source_relative:./proto --go-drpc_out=json=false,paths=source_relative:./proto proto/test.proto

View File

@@ -0,0 +1,216 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.15.6
// source: test.proto
package pb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
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 CallReq struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
}
func (x *CallReq) Reset() {
*x = CallReq{}
if protoimpl.UnsafeEnabled {
mi := &file_test_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *CallReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*CallReq) ProtoMessage() {}
func (x *CallReq) ProtoReflect() protoreflect.Message {
mi := &file_test_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)
}
// Deprecated: Use CallReq.ProtoReflect.Descriptor instead.
func (*CallReq) Descriptor() ([]byte, []int) {
return file_test_proto_rawDescGZIP(), []int{0}
}
func (x *CallReq) GetName() string {
if x != nil {
return x.Name
}
return ""
}
type CallRsp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
}
func (x *CallRsp) Reset() {
*x = CallRsp{}
if protoimpl.UnsafeEnabled {
mi := &file_test_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *CallRsp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*CallRsp) ProtoMessage() {}
func (x *CallRsp) ProtoReflect() protoreflect.Message {
mi := &file_test_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)
}
// Deprecated: Use CallRsp.ProtoReflect.Descriptor instead.
func (*CallRsp) Descriptor() ([]byte, []int) {
return file_test_proto_rawDescGZIP(), []int{1}
}
func (x *CallRsp) GetName() string {
if x != nil {
return x.Name
}
return ""
}
var File_test_proto protoreflect.FileDescriptor
var file_test_proto_rawDesc = []byte{
0x0a, 0x0a, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x54, 0x65,
0x73, 0x74, 0x22, 0x1d, 0x0a, 0x07, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a,
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d,
0x65, 0x22, 0x1d, 0x0a, 0x07, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x73, 0x70, 0x12, 0x12, 0x0a, 0x04,
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65,
0x32, 0x5e, 0x0a, 0x0b, 0x54, 0x65, 0x73, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12,
0x26, 0x0a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x12, 0x0d, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x2e, 0x43,
0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x1a, 0x0d, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61,
0x6c, 0x6c, 0x52, 0x73, 0x70, 0x22, 0x00, 0x12, 0x27, 0x0a, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f,
0x12, 0x0d, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x1a,
0x0d, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x73, 0x70, 0x22, 0x00,
0x42, 0x3a, 0x5a, 0x38, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x75,
0x6e, 0x69, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x2d, 0x6f, 0x72, 0x67, 0x2f, 0x6d, 0x69, 0x63, 0x72,
0x6f, 0x2d, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2f, 0x64,
0x72, 0x70, 0x63, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x33,
}
var (
file_test_proto_rawDescOnce sync.Once
file_test_proto_rawDescData = file_test_proto_rawDesc
)
func file_test_proto_rawDescGZIP() []byte {
file_test_proto_rawDescOnce.Do(func() {
file_test_proto_rawDescData = protoimpl.X.CompressGZIP(file_test_proto_rawDescData)
})
return file_test_proto_rawDescData
}
var file_test_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_test_proto_goTypes = []interface{}{
(*CallReq)(nil), // 0: Test.CallReq
(*CallRsp)(nil), // 1: Test.CallRsp
}
var file_test_proto_depIdxs = []int32{
0, // 0: Test.TestService.Call:input_type -> Test.CallReq
0, // 1: Test.TestService.Hello:input_type -> Test.CallReq
1, // 2: Test.TestService.Call:output_type -> Test.CallRsp
1, // 3: Test.TestService.Hello:output_type -> Test.CallRsp
2, // [2:4] is the sub-list for method output_type
0, // [0:2] 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_test_proto_init() }
func file_test_proto_init() {
if File_test_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_test_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*CallReq); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_test_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*CallRsp); 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_test_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_test_proto_goTypes,
DependencyIndexes: file_test_proto_depIdxs,
MessageInfos: file_test_proto_msgTypes,
}.Build()
File_test_proto = out.File
file_test_proto_rawDesc = nil
file_test_proto_goTypes = nil
file_test_proto_depIdxs = nil
}

View File

@@ -0,0 +1,18 @@
syntax = "proto3";
option go_package = "github.com/unistack-org/micro-tests/client/drpc/proto;pb";
package Test;
service TestService {
rpc Call(CallReq) returns (CallRsp) {}
rpc Hello(CallReq) returns (CallRsp) {}
}
message CallReq {
string name = 1;
}
message CallRsp {
string name = 1;
}

View File

@@ -0,0 +1,142 @@
// Code generated by protoc-gen-go-drpc. DO NOT EDIT.
// protoc-gen-go-drpc version: v0.0.23
// source: test.proto
package pb
import (
context "context"
errors "errors"
proto "google.golang.org/protobuf/proto"
drpc "storj.io/drpc"
drpcerr "storj.io/drpc/drpcerr"
)
type drpcEncoding_File_test_proto struct{}
func (drpcEncoding_File_test_proto) Marshal(msg drpc.Message) ([]byte, error) {
return proto.Marshal(msg.(proto.Message))
}
func (drpcEncoding_File_test_proto) MarshalAppend(buf []byte, msg drpc.Message) ([]byte, error) {
return proto.MarshalOptions{}.MarshalAppend(buf, msg.(proto.Message))
}
func (drpcEncoding_File_test_proto) Unmarshal(buf []byte, msg drpc.Message) error {
return proto.Unmarshal(buf, msg.(proto.Message))
}
type DRPCTestServiceClient interface {
DRPCConn() drpc.Conn
Call(ctx context.Context, in *CallReq) (*CallRsp, error)
Hello(ctx context.Context, in *CallReq) (*CallRsp, error)
}
type drpcTestServiceClient struct {
cc drpc.Conn
}
func NewDRPCTestServiceClient(cc drpc.Conn) DRPCTestServiceClient {
return &drpcTestServiceClient{cc}
}
func (c *drpcTestServiceClient) DRPCConn() drpc.Conn { return c.cc }
func (c *drpcTestServiceClient) Call(ctx context.Context, in *CallReq) (*CallRsp, error) {
out := new(CallRsp)
err := c.cc.Invoke(ctx, "/Test.TestService/Call", drpcEncoding_File_test_proto{}, in, out)
if err != nil {
return nil, err
}
return out, nil
}
func (c *drpcTestServiceClient) Hello(ctx context.Context, in *CallReq) (*CallRsp, error) {
out := new(CallRsp)
err := c.cc.Invoke(ctx, "/Test.TestService/Hello", drpcEncoding_File_test_proto{}, in, out)
if err != nil {
return nil, err
}
return out, nil
}
type DRPCTestServiceServer interface {
Call(context.Context, *CallReq) (*CallRsp, error)
Hello(context.Context, *CallReq) (*CallRsp, error)
}
type DRPCTestServiceUnimplementedServer struct{}
func (s *DRPCTestServiceUnimplementedServer) Call(context.Context, *CallReq) (*CallRsp, error) {
return nil, drpcerr.WithCode(errors.New("Unimplemented"), 12)
}
func (s *DRPCTestServiceUnimplementedServer) Hello(context.Context, *CallReq) (*CallRsp, error) {
return nil, drpcerr.WithCode(errors.New("Unimplemented"), 12)
}
type DRPCTestServiceDescription struct{}
func (DRPCTestServiceDescription) NumMethods() int { return 2 }
func (DRPCTestServiceDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) {
switch n {
case 0:
return "/Test.TestService/Call", drpcEncoding_File_test_proto{},
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
return srv.(DRPCTestServiceServer).
Call(
ctx,
in1.(*CallReq),
)
}, DRPCTestServiceServer.Call, true
case 1:
return "/Test.TestService/Hello", drpcEncoding_File_test_proto{},
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
return srv.(DRPCTestServiceServer).
Hello(
ctx,
in1.(*CallReq),
)
}, DRPCTestServiceServer.Hello, true
default:
return "", nil, nil, nil, false
}
}
func DRPCRegisterTestService(mux drpc.Mux, impl DRPCTestServiceServer) error {
return mux.Register(impl, DRPCTestServiceDescription{})
}
type DRPCTestService_CallStream interface {
drpc.Stream
SendAndClose(*CallRsp) error
}
type drpcTestService_CallStream struct {
drpc.Stream
}
func (x *drpcTestService_CallStream) SendAndClose(m *CallRsp) error {
if err := x.MsgSend(m, drpcEncoding_File_test_proto{}); err != nil {
return err
}
return x.CloseSend()
}
type DRPCTestService_HelloStream interface {
drpc.Stream
SendAndClose(*CallRsp) error
}
type drpcTestService_HelloStream struct {
drpc.Stream
}
func (x *drpcTestService_HelloStream) SendAndClose(m *CallRsp) error {
if err := x.MsgSend(m, drpcEncoding_File_test_proto{}); err != nil {
return err
}
return x.CloseSend()
}

View File

@@ -0,0 +1,29 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v3.4.0
// source: test.proto
package pb
import (
context "context"
api "github.com/unistack-org/micro/v3/api"
client "github.com/unistack-org/micro/v3/client"
)
var (
TestServiceEndpoints = []api.Endpoint{}
)
func NewTestServiceEndpoints() []api.Endpoint {
return TestServiceEndpoints
}
type TestServiceClient interface {
Call(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error)
Hello(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error)
}
type TestServiceServer interface {
Call(ctx context.Context, req *CallReq, rsp *CallRsp) error
Hello(ctx context.Context, req *CallReq, rsp *CallRsp) error
}

View File

@@ -0,0 +1,67 @@
// Code generated by protoc-gen-go-micro. DO NOT EDIT.
// protoc-gen-go-micro version: v3.4.0
// source: test.proto
package pb
import (
context "context"
api "github.com/unistack-org/micro/v3/api"
client "github.com/unistack-org/micro/v3/client"
server "github.com/unistack-org/micro/v3/server"
)
type testServiceClient struct {
c client.Client
name string
}
func NewTestServiceClient(name string, c client.Client) TestServiceClient {
return &testServiceClient{c: c, name: name}
}
func (c *testServiceClient) Call(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error) {
rsp := &CallRsp{}
err := c.c.Call(ctx, c.c.NewRequest(c.name, "TestService.Call", req), rsp, opts...)
if err != nil {
return nil, err
}
return rsp, nil
}
func (c *testServiceClient) Hello(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error) {
rsp := &CallRsp{}
err := c.c.Call(ctx, c.c.NewRequest(c.name, "TestService.Hello", req), rsp, opts...)
if err != nil {
return nil, err
}
return rsp, nil
}
type testServiceServer struct {
TestServiceServer
}
func (h *testServiceServer) Call(ctx context.Context, req *CallReq, rsp *CallRsp) error {
return h.TestServiceServer.Call(ctx, req, rsp)
}
func (h *testServiceServer) Hello(ctx context.Context, req *CallReq, rsp *CallRsp) error {
return h.TestServiceServer.Hello(ctx, req, rsp)
}
func RegisterTestServiceServer(s server.Server, sh TestServiceServer, opts ...server.HandlerOption) error {
type testService interface {
Call(ctx context.Context, req *CallReq, rsp *CallRsp) error
Hello(ctx context.Context, req *CallReq, rsp *CallRsp) error
}
type TestService struct {
testService
}
h := &testServiceServer{sh}
var nopts []server.HandlerOption
for _, endpoint := range TestServiceEndpoints {
nopts = append(nopts, api.WithEndpoint(&endpoint))
}
return s.Handle(s.NewHandler(&TestService{h}, append(nopts, opts...)...))
}

7
client/drpc/tools.go Normal file
View File

@@ -0,0 +1,7 @@
// +build tools
package drpc
import (
_ "storj.io/drpc/cmd/protoc-gen-go-drpc"
)