config_test.go 1.2 KB

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