github.com/shuguocloud/go-zero@v1.3.0/zrpc/internal/client_test.go (about) 1 package internal 2 3 import ( 4 "context" 5 "testing" 6 "time" 7 8 "github.com/stretchr/testify/assert" 9 "google.golang.org/grpc" 10 ) 11 12 func TestWithDialOption(t *testing.T) { 13 var options ClientOptions 14 agent := grpc.WithUserAgent("chrome") 15 opt := WithDialOption(agent) 16 opt(&options) 17 assert.Contains(t, options.DialOptions, agent) 18 } 19 20 func TestWithTimeout(t *testing.T) { 21 var options ClientOptions 22 opt := WithTimeout(time.Second) 23 opt(&options) 24 assert.Equal(t, time.Second, options.Timeout) 25 } 26 27 func TestWithNonBlock(t *testing.T) { 28 var options ClientOptions 29 opt := WithNonBlock() 30 opt(&options) 31 assert.True(t, options.NonBlock) 32 } 33 34 func TestWithTransportCredentials(t *testing.T) { 35 var options ClientOptions 36 opt := WithTransportCredentials(nil) 37 opt(&options) 38 assert.Equal(t, 1, len(options.DialOptions)) 39 } 40 41 func TestWithUnaryClientInterceptor(t *testing.T) { 42 var options ClientOptions 43 opt := WithUnaryClientInterceptor(func(ctx context.Context, method string, req, reply interface{}, 44 cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { 45 return nil 46 }) 47 opt(&options) 48 assert.Equal(t, 1, len(options.DialOptions)) 49 } 50 51 func TestBuildDialOptions(t *testing.T) { 52 var c client 53 agent := grpc.WithUserAgent("chrome") 54 opts := c.buildDialOptions(WithDialOption(agent)) 55 assert.Contains(t, opts, agent) 56 }