go-zero/zrpc/internal/client_test.go

32 lines
659 B
Go
Raw Normal View History

2020-08-25 22:42:42 +08:00
package internal
import (
"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 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)
}