|
|
|
@ -9,6 +9,7 @@ import (
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"github.com/tal-tech/go-zero/core/discov"
|
|
|
|
|
"github.com/tal-tech/go-zero/core/logx"
|
|
|
|
|
"github.com/tal-tech/go-zero/zrpc/internal/mock"
|
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
@ -82,6 +83,20 @@ func TestDepositServer_Deposit(t *testing.T) {
|
|
|
|
|
return invoker(ctx, method, req, reply, cc, opts...)
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
tarConfClient := MustNewClient(
|
|
|
|
|
RpcClientConf{
|
|
|
|
|
Target: "foo",
|
|
|
|
|
App: "foo",
|
|
|
|
|
Token: "bar",
|
|
|
|
|
Timeout: 1000,
|
|
|
|
|
},
|
|
|
|
|
WithDialOption(grpc.WithInsecure()),
|
|
|
|
|
WithDialOption(grpc.WithContextDialer(dialer())),
|
|
|
|
|
WithUnaryClientInterceptor(func(ctx context.Context, method string, req, reply interface{},
|
|
|
|
|
cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
|
|
|
|
return invoker(ctx, method, req, reply, cc, opts...)
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
targetClient, err := NewClientWithTarget("foo", WithDialOption(grpc.WithInsecure()),
|
|
|
|
|
WithDialOption(grpc.WithContextDialer(dialer())), WithUnaryClientInterceptor(
|
|
|
|
|
func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn,
|
|
|
|
@ -91,11 +106,15 @@ func TestDepositServer_Deposit(t *testing.T) {
|
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
clients := []Client{
|
|
|
|
|
directClient,
|
|
|
|
|
tarConfClient,
|
|
|
|
|
targetClient,
|
|
|
|
|
}
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
tt := tt
|
|
|
|
|
for _, client := range clients {
|
|
|
|
|
client := client
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
cli := mock.NewDepositServiceClient(client.Conn())
|
|
|
|
|
request := &mock.DepositRequest{Amount: tt.amount}
|
|
|
|
|
response, err := cli.Deposit(context.Background(), request)
|
|
|
|
@ -119,3 +138,39 @@ func TestDepositServer_Deposit(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestNewClientWithError(t *testing.T) {
|
|
|
|
|
_, err := NewClient(
|
|
|
|
|
RpcClientConf{
|
|
|
|
|
App: "foo",
|
|
|
|
|
Token: "bar",
|
|
|
|
|
Timeout: 1000,
|
|
|
|
|
},
|
|
|
|
|
WithDialOption(grpc.WithInsecure()),
|
|
|
|
|
WithDialOption(grpc.WithContextDialer(dialer())),
|
|
|
|
|
WithUnaryClientInterceptor(func(ctx context.Context, method string, req, reply interface{},
|
|
|
|
|
cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
|
|
|
|
return invoker(ctx, method, req, reply, cc, opts...)
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
|
|
|
|
|
_, err = NewClient(
|
|
|
|
|
RpcClientConf{
|
|
|
|
|
Etcd: discov.EtcdConf{
|
|
|
|
|
Hosts: []string{"localhost:2379"},
|
|
|
|
|
Key: "mock",
|
|
|
|
|
},
|
|
|
|
|
App: "foo",
|
|
|
|
|
Token: "bar",
|
|
|
|
|
Timeout: 1,
|
|
|
|
|
},
|
|
|
|
|
WithDialOption(grpc.WithInsecure()),
|
|
|
|
|
WithDialOption(grpc.WithContextDialer(dialer())),
|
|
|
|
|
WithUnaryClientInterceptor(func(ctx context.Context, method string, req, reply interface{},
|
|
|
|
|
cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
|
|
|
|
return invoker(ctx, method, req, reply, cc, opts...)
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
|
}
|
|
|
|
|