github.com/lingyao2333/mo-zero@v1.4.1/zrpc/config_test.go (about) 1 package zrpc 2 3 import ( 4 "testing" 5 6 "github.com/lingyao2333/mo-zero/core/discov" 7 "github.com/lingyao2333/mo-zero/core/service" 8 "github.com/lingyao2333/mo-zero/core/stores/redis" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestRpcClientConf(t *testing.T) { 13 conf := NewDirectClientConf([]string{"localhost:1234"}, "foo", "bar") 14 assert.True(t, conf.HasCredential()) 15 conf = NewEtcdClientConf([]string{"localhost:1234", "localhost:5678"}, "key", "foo", "bar") 16 assert.True(t, conf.HasCredential()) 17 } 18 19 func TestRpcServerConf(t *testing.T) { 20 conf := RpcServerConf{ 21 ServiceConf: service.ServiceConf{}, 22 ListenOn: "", 23 Etcd: discov.EtcdConf{ 24 Hosts: []string{"localhost:1234"}, 25 Key: "key", 26 }, 27 Auth: true, 28 Redis: redis.RedisKeyConf{ 29 RedisConf: redis.RedisConf{ 30 Type: redis.NodeType, 31 }, 32 Key: "foo", 33 }, 34 StrictControl: false, 35 Timeout: 0, 36 CpuThreshold: 0, 37 } 38 assert.True(t, conf.HasEtcd()) 39 assert.NotNil(t, conf.Validate()) 40 conf.Redis.Host = "localhost:5678" 41 assert.Nil(t, conf.Validate()) 42 }