forked from zeromicro/go-zero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
67 lines (60 loc) · 1.64 KB
/
config_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package zrpc
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/zeromicro/go-zero/core/discov"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/core/stores/redis"
)
func TestRpcClientConf(t *testing.T) {
t.Run("direct", func(t *testing.T) {
conf := NewDirectClientConf([]string{"localhost:1234"}, "foo", "bar")
assert.True(t, conf.HasCredential())
})
t.Run("etcd", func(t *testing.T) {
conf := NewEtcdClientConf([]string{"localhost:1234", "localhost:5678"},
"key", "foo", "bar")
assert.True(t, conf.HasCredential())
})
t.Run("etcd with account", func(t *testing.T) {
conf := NewEtcdClientConf([]string{"localhost:1234", "localhost:5678"},
"key", "foo", "bar")
conf.Etcd.User = "user"
conf.Etcd.Pass = "pass"
_, err := conf.BuildTarget()
assert.NoError(t, err)
})
t.Run("etcd with tls", func(t *testing.T) {
conf := NewEtcdClientConf([]string{"localhost:1234", "localhost:5678"},
"key", "foo", "bar")
conf.Etcd.CertFile = "cert"
conf.Etcd.CertKeyFile = "key"
conf.Etcd.CACertFile = "ca"
_, err := conf.BuildTarget()
assert.Error(t, err)
})
}
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())
}