From 1a8014c704d6daae6fa5de9ce061a9f505b2a846 Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 26 Aug 2020 14:32:35 +0800 Subject: [PATCH] add more tests --- rpcx/config_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 rpcx/config_test.go diff --git a/rpcx/config_test.go b/rpcx/config_test.go new file mode 100644 index 00000000..e9b45c29 --- /dev/null +++ b/rpcx/config_test.go @@ -0,0 +1,42 @@ +package rpcx + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/tal-tech/go-zero/core/discov" + "github.com/tal-tech/go-zero/core/service" + "github.com/tal-tech/go-zero/core/stores/redis" +) + +func TestRpcClientConf(t *testing.T) { + conf := NewDirectClientConf([]string{"localhost:1234"}, "foo", "bar") + assert.True(t, conf.HasCredential()) + conf = NewEtcdClientConf([]string{"localhost:1234", "localhost:5678"}, "key", "foo", "bar") + assert.True(t, conf.HasCredential()) +} + +func TestRpcServerConf(t *testing.T) { + conf := RpcServerConf{ + ServiceConf: service.ServiceConf{}, + ListenOn: "", + Etcd: discov.EtcdConf{ + Hosts: []string{"localhost:1234"}, + Key: "key", + }, + Auth: true, + Redis: redis.RedisKeyConf{ + RedisConf: redis.RedisConf{ + Type: redis.NodeType, + }, + Key: "foo", + }, + StrictControl: false, + Timeout: 0, + CpuThreshold: 0, + } + assert.True(t, conf.HasEtcd()) + assert.NotNil(t, conf.Validate()) + conf.Redis.Host = "localhost:5678" + assert.Nil(t, conf.Validate()) +}