go-zero/zrpc/internal/client_test.go

43 lines
1013 B
Go
Raw Normal View History

2020-08-25 22:42:42 +08:00
package internal
import (
"context"
2020-08-25 22:42:42 +08:00
"testing"
"time"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
)
func TestWithDialOption(t *testing.T) {
var options ClientOptions
agent := grpc.WithUserAgent("chrome")
opt := WithDialOption(agent)
opt(&options)
assert.Contains(t, options.DialOptions, agent)
}
func TestWithTimeout(t *testing.T) {
var options ClientOptions
opt := WithTimeout(time.Second)
opt(&options)
assert.Equal(t, time.Second, options.Timeout)
}
func TestWithUnaryClientInterceptor(t *testing.T) {
var options ClientOptions
opt := WithUnaryClientInterceptor(func(ctx context.Context, method string, req, reply interface{},
cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
return nil
})
opt(&options)
assert.Equal(t, 1, len(options.DialOptions))
}
2020-08-25 22:42:42 +08:00
func TestBuildDialOptions(t *testing.T) {
2020-09-29 16:09:11 +08:00
var c client
2020-08-25 22:42:42 +08:00
agent := grpc.WithUserAgent("chrome")
2020-09-29 16:09:11 +08:00
opts := c.buildDialOptions(WithDialOption(agent))
2020-08-25 22:42:42 +08:00
assert.Contains(t, opts, agent)
}