config_test.go 1020 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package zrpc
  2. import (
  3. "testing"
  4. "git.i2edu.net/i2/go-zero/core/discov"
  5. "git.i2edu.net/i2/go-zero/core/service"
  6. "git.i2edu.net/i2/go-zero/core/stores/redis"
  7. "github.com/stretchr/testify/assert"
  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. }
  15. func TestRpcServerConf(t *testing.T) {
  16. conf := RpcServerConf{
  17. ServiceConf: service.ServiceConf{},
  18. ListenOn: "",
  19. Etcd: discov.EtcdConf{
  20. Hosts: []string{"localhost:1234"},
  21. Key: "key",
  22. },
  23. Auth: true,
  24. Redis: redis.RedisKeyConf{
  25. RedisConf: redis.RedisConf{
  26. Type: redis.NodeType,
  27. },
  28. Key: "foo",
  29. },
  30. StrictControl: false,
  31. Timeout: 0,
  32. CpuThreshold: 0,
  33. }
  34. assert.True(t, conf.HasEtcd())
  35. assert.NotNil(t, conf.Validate())
  36. conf.Redis.Host = "localhost:5678"
  37. assert.Nil(t, conf.Validate())
  38. }