update tests

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-03-09 14:25:27 +03:00
parent 1fe22608bb
commit a1b7e6cc71
9 changed files with 176 additions and 48 deletions

View File

@ -21,12 +21,15 @@ service Github {
option (micro.api.http) = { get: "/users/{username}"; };
};
};
message LookupUserReq {
string username = 1;
};
message LookupUserRsp {
string name = 1;
};
message Error {
string message = 1;
};

2
go.mod
View File

@ -27,7 +27,7 @@ require (
github.com/unistack-org/micro-proto v0.0.2-0.20210227213711-77c7563bd01e
github.com/unistack-org/micro-router-register/v3 v3.2.2
github.com/unistack-org/micro-server-grpc/v3 v3.2.4
github.com/unistack-org/micro-server-http/v3 v3.2.9
github.com/unistack-org/micro-server-http/v3 v3.2.10
github.com/unistack-org/micro-server-tcp/v3 v3.2.2
github.com/unistack-org/micro-wrapper-trace-opentracing/v3 v3.2.0
github.com/unistack-org/micro/v3 v3.2.20

7
go.sum
View File

@ -473,8 +473,8 @@ github.com/unistack-org/micro-router-register/v3 v3.2.2 h1:lYCymDHkJfhZWYQ4+Sb7F
github.com/unistack-org/micro-router-register/v3 v3.2.2/go.mod h1:Y9Qtlg4NHqq5rR6X6Jm+04LoSJMi7/OOCm2mRueZYTE=
github.com/unistack-org/micro-server-grpc/v3 v3.2.4 h1:C/vkzkZ0rpzLIYiaIK53kk5KIfBox2JCbqLvMwz0lWI=
github.com/unistack-org/micro-server-grpc/v3 v3.2.4/go.mod h1:ZtCwgb0E7vS4C9GBqpLCNpyQs8TrHQSh4Q0RuNiWE7Y=
github.com/unistack-org/micro-server-http/v3 v3.2.9 h1:m5od6wCmx58Vzmbrhm+uYNNpN3AGT+RXdzf4cAszPTc=
github.com/unistack-org/micro-server-http/v3 v3.2.9/go.mod h1:TUIksrJUzTnH13Qs4skgEyADvMLK/3JgzjJ4Sx/yxN4=
github.com/unistack-org/micro-server-http/v3 v3.2.10 h1:YYzwaa9Lcbm5TSU+94PbAGHNK0FQ5CSNuAg55rHtgFw=
github.com/unistack-org/micro-server-http/v3 v3.2.10/go.mod h1:HRA02Jwe6DoSoOyLidu8RJfRa4aItckGIwyn7pCVaqw=
github.com/unistack-org/micro-server-tcp/v3 v3.2.2 h1:2/Xn+4+dnzY/tpD3MgLO1wg3ect9Jx5CLSDfPBjdjT4=
github.com/unistack-org/micro-server-tcp/v3 v3.2.2/go.mod h1:TQDIck2+RdEAGIRnwv+2a0OVBUTkL6OM7YUY4AjFFmY=
github.com/unistack-org/micro-wrapper-trace-opentracing/v3 v3.2.0 h1:PvemkpeCVUWfCoKwt1XmJ8uGK9My/7T29qOVxtYJohw=
@ -487,8 +487,7 @@ github.com/unistack-org/micro/v3 v3.2.11/go.mod h1:uGPB8BhDWHj63tR3eaoCd3X+lPtAg
github.com/unistack-org/micro/v3 v3.2.14/go.mod h1:3j13mSd/rILNjyP0tEVtDxyDkJBtnHUXShNCuPHkC5A=
github.com/unistack-org/micro/v3 v3.2.15/go.mod h1:y+fV+BPNK2IqGoLquRU396jTYifG0HCw3zxFfI4E0dc=
github.com/unistack-org/micro/v3 v3.2.16/go.mod h1:y+fV+BPNK2IqGoLquRU396jTYifG0HCw3zxFfI4E0dc=
github.com/unistack-org/micro/v3 v3.2.19 h1:UkiudIMOBD8SS1jnSVUPEfi0CYRVmkm37/2keUkA2p0=
github.com/unistack-org/micro/v3 v3.2.19/go.mod h1:y+fV+BPNK2IqGoLquRU396jTYifG0HCw3zxFfI4E0dc=
github.com/unistack-org/micro/v3 v3.2.20 h1:EY94FDfHR43QvKNjmCaVH8/7+D8bmLwySXbFK9iIQY0=
github.com/unistack-org/micro/v3 v3.2.20/go.mod h1:y+fV+BPNK2IqGoLquRU396jTYifG0HCw3zxFfI4E0dc=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=

View File

@ -1,5 +1,5 @@
package http
///go:generate protoc -I./proto -I. -I/home/vtolstov/.cache/go-path/pkg/mod/github.com/unistack-org/micro-proto@v0.0.1 --go_out=paths=source_relative:./proto --micro_out=components=micro|http,debug=true,paths=source_relative:./proto proto/test.proto
//go:generate protoc -I./proto -I. -I/home/vtolstov/.cache/go-path/pkg/mod/github.com/unistack-org/micro-proto@v0.0.1 --go_out=paths=source_relative:./proto --micro_out=components=micro|http,debug=true,paths=source_relative:./proto proto/test.proto
//go:generate protoc -I./proto -I. -I/home/vtolstov/devel/projects/unistack/micro/micro-proto --go_out=paths=source_relative:./proto --micro_out=components=micro|http,debug=true,paths=source_relative:./proto proto/test.proto
///go:generate protoc -I./proto -I. -I/home/vtolstov/devel/projects/unistack/micro/micro-proto --go_out=paths=source_relative:./proto --micro_out=components=micro|http,debug=true,paths=source_relative:./proto proto/test.proto

View File

@ -34,6 +34,12 @@ func NewServerHandlerWrapper() server.HandlerWrapper {
}
}
func (h *Handler) CallDouble(ctx context.Context, req *pb.CallReq, rsp *pb.CallRsp) error {
rsp.Rsp = "name_double"
httpsrv.SetRspCode(ctx, http.StatusCreated)
return nil
}
func (h *Handler) Call(ctx context.Context, req *pb.CallReq, rsp *pb.CallRsp) error {
if req.Nested == nil {
h.t.Fatalf("invalid reflect merging")
@ -87,7 +93,18 @@ func TestNativeClientServer(t *testing.T) {
)
h := &Handler{t: t}
pb.RegisterTestServer(srv, h)
// init server
if err := srv.Init(); err != nil {
t.Fatal(err)
}
if err := pb.RegisterTestServer(srv, h); err != nil {
t.Fatal(err)
}
if err := pb.RegisterTestDoubleServer(srv, h); err != nil {
t.Fatal(err)
}
// start server
if err := srv.Start(); err != nil {
@ -110,8 +127,8 @@ func TestNativeClientServer(t *testing.T) {
cli := client.NewClientCallOptions(httpcli.NewClient(client.ContentType("application/json"), client.Codec("application/json", jsonpbcodec.NewCodec())), client.WithAddress(fmt.Sprintf("http://%s", service[0].Nodes[0].Address)))
svc := pb.NewTestClient("helloworld", cli)
rsp, err := svc.Call(ctx, &pb.CallReq{
svc1 := pb.NewTestClient("helloworld", cli)
rsp, err := svc1.Call(ctx, &pb.CallReq{
Name: "my_name",
Nested: &pb.Nested{Uint64Args: []*wrapperpb.UInt64Value{
&wrapperpb.UInt64Value{Value: 1},
@ -130,6 +147,20 @@ func TestNativeClientServer(t *testing.T) {
if !mwfOk {
t.Fatalf("http middleware not works")
}
t.Logf("test second server")
svc2 := pb.NewTestDoubleClient("helloworld", cli)
rsp, err = svc2.CallDouble(ctx, &pb.CallReq{
Name: "my_name",
})
if err != nil {
t.Fatal(err)
}
if rsp.Rsp != "name_double" {
t.Fatalf("invalid response: %#+v\n", rsp)
}
// stop server
if err := srv.Stop(); err != nil {
t.Fatal(err)

View File

@ -390,30 +390,38 @@ var file_test_proto_rawDesc = []byte{
0x0a, 0x08, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x73, 0x70, 0x31, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x73,
0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x72, 0x73, 0x70, 0x22, 0x19, 0x0a, 0x05,
0x45, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x32, 0xaf, 0x02, 0x0a, 0x04, 0x54, 0x65, 0x73, 0x74,
0x12, 0x84, 0x01, 0x0a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x12, 0x0d, 0x2e, 0x74, 0x65, 0x73, 0x74,
0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x1a, 0x0d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e,
0x43, 0x61, 0x6c, 0x6c, 0x52, 0x73, 0x70, 0x22, 0x5e, 0x92, 0x41, 0x34, 0x2a, 0x04, 0x43, 0x61,
0x6c, 0x6c, 0x4a, 0x2c, 0x0a, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x21, 0x0a,
0x0e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12,
0x0f, 0x0a, 0x0d, 0x1a, 0x0b, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72,
0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x22, 0x14, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x65, 0x73, 0x74,
0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x3a, 0x01, 0x2a, 0xba,
0xea, 0xff, 0xf9, 0x01, 0x02, 0x08, 0x05, 0x12, 0x8d, 0x01, 0x0a, 0x09, 0x43, 0x61, 0x6c, 0x6c,
0x45, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x0e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c,
0x6c, 0x52, 0x65, 0x71, 0x31, 0x1a, 0x0e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c,
0x6c, 0x52, 0x73, 0x70, 0x31, 0x22, 0x60, 0x92, 0x41, 0x39, 0x2a, 0x09, 0x43, 0x61, 0x6c, 0x6c,
0x45, 0x72, 0x72, 0x6f, 0x72, 0x4a, 0x2c, 0x0a, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74,
0x12, 0x21, 0x0a, 0x0e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x12, 0x0f, 0x0a, 0x0d, 0x1a, 0x0b, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x72,
0x72, 0x6f, 0x72, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1e, 0x22, 0x19, 0x2f, 0x76, 0x31, 0x2f, 0x74,
0x65, 0x73, 0x74, 0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x2f, 0x7b, 0x6e,
0x61, 0x6d, 0x65, 0x7d, 0x3a, 0x01, 0x2a, 0x1a, 0x10, 0xba, 0xea, 0xff, 0xf9, 0x01, 0x0a, 0x12,
0x03, 0x6f, 0x6e, 0x65, 0x12, 0x03, 0x74, 0x77, 0x6f, 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, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x68, 0x74, 0x74, 0x70, 0x2f, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x32, 0x97, 0x01, 0x0a, 0x0a, 0x54, 0x65, 0x73, 0x74,
0x44, 0x6f, 0x75, 0x62, 0x6c, 0x65, 0x12, 0x88, 0x01, 0x0a, 0x0a, 0x43, 0x61, 0x6c, 0x6c, 0x44,
0x6f, 0x75, 0x62, 0x6c, 0x65, 0x12, 0x0d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c,
0x6c, 0x52, 0x65, 0x71, 0x1a, 0x0d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c, 0x6c,
0x52, 0x73, 0x70, 0x22, 0x5c, 0x92, 0x41, 0x34, 0x2a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x4a, 0x2c,
0x0a, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x21, 0x0a, 0x0e, 0x45, 0x72, 0x72,
0x6f, 0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0f, 0x0a, 0x0d, 0x1a,
0x0b, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x82, 0xd3, 0xe4, 0x93,
0x02, 0x1f, 0x22, 0x1a, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x64, 0x6f, 0x75, 0x62,
0x6c, 0x65, 0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x2f, 0x7b, 0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x3a, 0x01,
0x2a, 0x32, 0x94, 0x02, 0x0a, 0x04, 0x54, 0x65, 0x73, 0x74, 0x12, 0x7c, 0x0a, 0x04, 0x43, 0x61,
0x6c, 0x6c, 0x12, 0x0d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x65,
0x71, 0x1a, 0x0d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61, 0x6c, 0x6c, 0x52, 0x73, 0x70,
0x22, 0x56, 0x92, 0x41, 0x34, 0x2a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x4a, 0x2c, 0x0a, 0x07, 0x64,
0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x21, 0x0a, 0x0e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20,
0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0f, 0x0a, 0x0d, 0x1a, 0x0b, 0x2e, 0x74,
0x65, 0x73, 0x74, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x22,
0x14, 0x2f, 0x76, 0x31, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x2f, 0x7b,
0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x3a, 0x01, 0x2a, 0x12, 0x8d, 0x01, 0x0a, 0x09, 0x43, 0x61, 0x6c,
0x6c, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x0e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61,
0x6c, 0x6c, 0x52, 0x65, 0x71, 0x31, 0x1a, 0x0e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x43, 0x61,
0x6c, 0x6c, 0x52, 0x73, 0x70, 0x31, 0x22, 0x60, 0x92, 0x41, 0x39, 0x2a, 0x09, 0x43, 0x61, 0x6c,
0x6c, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x4a, 0x2c, 0x0a, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c,
0x74, 0x12, 0x21, 0x0a, 0x0e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x12, 0x0f, 0x0a, 0x0d, 0x1a, 0x0b, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x45,
0x72, 0x72, 0x6f, 0x72, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1e, 0x22, 0x19, 0x2f, 0x76, 0x31, 0x2f,
0x74, 0x65, 0x73, 0x74, 0x2f, 0x63, 0x61, 0x6c, 0x6c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x2f, 0x7b,
0x6e, 0x61, 0x6d, 0x65, 0x7d, 0x3a, 0x01, 0x2a, 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,
0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x68, 0x74, 0x74, 0x70, 0x2f, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -441,12 +449,14 @@ var file_test_proto_goTypes = []interface{}{
var file_test_proto_depIdxs = []int32{
1, // 0: test.CallReq.nested:type_name -> test.Nested
6, // 1: test.Nested.uint64_args:type_name -> google.protobuf.UInt64Value
0, // 2: test.Test.Call:input_type -> test.CallReq
3, // 3: test.Test.CallError:input_type -> test.CallReq1
2, // 4: test.Test.Call:output_type -> test.CallRsp
4, // 5: test.Test.CallError:output_type -> test.CallRsp1
4, // [4:6] is the sub-list for method output_type
2, // [2:4] is the sub-list for method input_type
0, // 2: test.TestDouble.CallDouble:input_type -> test.CallReq
0, // 3: test.Test.Call:input_type -> test.CallReq
3, // 4: test.Test.CallError:input_type -> test.CallReq1
2, // 5: test.TestDouble.CallDouble:output_type -> test.CallRsp
2, // 6: test.Test.Call:output_type -> test.CallRsp
4, // 7: test.Test.CallError:output_type -> test.CallRsp1
5, // [5:8] is the sub-list for method output_type
2, // [2:5] is the sub-list for method input_type
2, // [2:2] is the sub-list for extension type_name
2, // [2:2] is the sub-list for extension extendee
0, // [0:2] is the sub-list for field type_name
@ -539,7 +549,7 @@ func file_test_proto_init() {
NumEnums: 0,
NumMessages: 6,
NumExtensions: 0,
NumServices: 1,
NumServices: 2,
},
GoTypes: file_test_proto_goTypes,
DependencyIndexes: file_test_proto_depIdxs,

View File

@ -8,8 +8,30 @@ import "api/annotations.proto";
import "openapiv2/annotations.proto";
import "google/protobuf/wrappers.proto";
service TestDouble {
//option (micro.api.micro_service) = { client_wrappers: ["one","two"]; };
rpc CallDouble(CallReq) returns (CallRsp) {
option (micro.openapiv2.openapiv2_operation) = {
operation_id: "Call";
responses: {
key: "default";
value: {
description: "Error response";
schema: {
json_schema: {
ref: ".test.Error";
}
}
}
}
};
option (micro.api.http) = { post: "/v1/testdouble/call/{name}"; body: "*"; };
//option (micro.api.micro_method) = { timeout: 5; };
};
};
service Test {
option (micro.api.micro_service) = { client_wrappers: ["one","two"]; };
//option (micro.api.micro_service) = { client_wrappers: ["one","two"]; };
rpc Call(CallReq) returns (CallRsp) {
option (micro.openapiv2.openapiv2_operation) = {
operation_id: "Call";
@ -26,7 +48,7 @@ service Test {
}
};
option (micro.api.http) = { post: "/v1/test/call/{name}"; body: "*"; };
option (micro.api.micro_method) = { timeout: 5; };
//option (micro.api.micro_method) = { timeout: 5; };
};
rpc CallError(CallReq1) returns (CallRsp1) {
option (micro.openapiv2.openapiv2_operation) = {

View File

@ -8,6 +8,26 @@ import (
client "github.com/unistack-org/micro/v3/client"
)
func NewTestDoubleEndpoints() []*api.Endpoint {
return []*api.Endpoint{
&api.Endpoint{
Name: "TestDouble.CallDouble",
Path: []string{"/v1/testdouble/call/{name}"},
Method: []string{"POST"},
Body: "*",
Handler: "rpc",
},
}
}
type TestDoubleClient interface {
CallDouble(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error)
}
type TestDoubleServer interface {
CallDouble(ctx context.Context, req *CallReq, rsp *CallRsp) error
}
func NewTestEndpoints() []*api.Endpoint {
return []*api.Endpoint{
&api.Endpoint{

View File

@ -8,9 +8,56 @@ import (
api "github.com/unistack-org/micro/v3/api"
client "github.com/unistack-org/micro/v3/client"
server "github.com/unistack-org/micro/v3/server"
time "time"
)
type testDoubleClient struct {
c client.Client
name string
}
func NewTestDoubleClient(name string, c client.Client) TestDoubleClient {
return &testDoubleClient{c: c, name: name}
}
func (c *testDoubleClient) CallDouble(ctx context.Context, req *CallReq, opts ...client.CallOption) (*CallRsp, error) {
errmap := make(map[string]interface{}, 1)
errmap["default"] = &Error{}
opts = append(opts,
v3.ErrorMap(errmap),
v3.Method("POST"),
v3.Path("/v1/testdouble/call/{name}"),
v3.Body("*"),
)
rsp := &CallRsp{}
err := c.c.Call(ctx, c.c.NewRequest(c.name, "TestDouble.CallDouble", req), rsp, opts...)
if err != nil {
return nil, err
}
return rsp, nil
}
type testDoubleServer struct {
TestDoubleServer
}
func (h *testDoubleServer) CallDouble(ctx context.Context, req *CallReq, rsp *CallRsp) error {
return h.TestDoubleServer.CallDouble(ctx, req, rsp)
}
func RegisterTestDoubleServer(s server.Server, sh TestDoubleServer, opts ...server.HandlerOption) error {
type testDouble interface {
CallDouble(ctx context.Context, req *CallReq, rsp *CallRsp) error
}
type TestDouble struct {
testDouble
}
h := &testDoubleServer{sh}
for _, endpoint := range NewTestDoubleEndpoints() {
opts = append(opts, api.WithEndpoint(endpoint))
}
return s.Handle(s.NewHandler(&TestDouble{h}, opts...))
}
type testClient struct {
c client.Client
name string
@ -29,7 +76,6 @@ func (c *testClient) Call(ctx context.Context, req *CallReq, opts ...client.Call
v3.Path("/v1/test/call/{name}"),
v3.Body("*"),
)
opts = append(opts, client.WithRequestTimeout(time.Second*5))
rsp := &CallRsp{}
err := c.c.Call(ctx, c.c.NewRequest(c.name, "Test.Call", req), rsp, opts...)
if err != nil {
@ -60,9 +106,6 @@ type testServer struct {
}
func (h *testServer) Call(ctx context.Context, req *CallReq, rsp *CallRsp) error {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, time.Second*5)
defer cancel()
return h.TestServer.Call(ctx, req, rsp)
}