-
Notifications
You must be signed in to change notification settings - Fork 36
/
options_test.go
157 lines (125 loc) · 3.66 KB
/
options_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package workers
import (
"crypto/tls"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestRedisPoolConfig(t *testing.T) {
// Tests redis pool size which defaults to 1
opts, err := processOptions(Options{
ServerAddr: "localhost:6379",
ProcessID: "2",
})
assert.NoError(t, err)
assert.Equal(t, 1, opts.client.Options().PoolSize)
opts, err = processOptions(Options{
ServerAddr: "localhost:6379",
ProcessID: "1",
PoolSize: 20,
})
assert.NoError(t, err)
assert.Equal(t, 20, opts.client.Options().PoolSize)
}
func TestRedisPoolConfigTLS(t *testing.T) {
opts, err := processOptions(Options{
ServerAddr: "localhost:6379",
ProcessID: "1",
PoolSize: 20,
})
assert.NoError(t, err)
assert.Nil(t, opts.client.Options().TLSConfig)
opts, err = processOptions(Options{
ServerAddr: "localhost:6379",
ProcessID: "1",
PoolSize: 20,
RedisTLSConfig: &tls.Config{ServerName: "test_tls"},
})
assert.NoError(t, err)
assert.NotNil(t, opts.client.Options().TLSConfig)
assert.Equal(t, "test_tls", opts.client.Options().TLSConfig.ServerName)
}
func TestCustomProcessConfig(t *testing.T) {
opts, err := processOptions(Options{
ServerAddr: "localhost:6379",
ProcessID: "1",
})
assert.NoError(t, err)
assert.Equal(t, "1", opts.ProcessID)
opts, err = processOptions(Options{
ServerAddr: "localhost:6379",
ProcessID: "2",
})
assert.NoError(t, err)
assert.Equal(t, "2", opts.ProcessID)
}
func TestRequiresRedisConfig(t *testing.T) {
_, err := processOptions(Options{ProcessID: "2"})
assert.Error(t, err, "Configure requires either the Server or Sentinels option")
}
func TestRequiresProcessConfig(t *testing.T) {
_, err := processOptions(Options{ServerAddr: "localhost:6379"})
assert.Error(t, err, "Configure requires a ProcessID, which uniquely identifies this instance")
}
func TestAddsColonToNamespace(t *testing.T) {
opts, err := processOptions(Options{
ServerAddr: "localhost:6379",
ProcessID: "1",
})
assert.NoError(t, err)
assert.Equal(t, "", opts.Namespace)
opts, err = processOptions(Options{
ServerAddr: "localhost:6379",
ProcessID: "1",
Namespace: "prod",
})
assert.NoError(t, err)
assert.Equal(t, "prod:", opts.Namespace)
}
func TestDefaultPollIntervalConfig(t *testing.T) {
opts, err := processOptions(Options{
ServerAddr: "localhost:6379",
ProcessID: "1",
})
assert.NoError(t, err)
assert.Equal(t, 15*time.Second, opts.PollInterval)
opts, err = processOptions(Options{
ServerAddr: "localhost:6379",
ProcessID: "1",
PollInterval: time.Second,
})
assert.NoError(t, err)
assert.Equal(t, time.Second, opts.PollInterval)
}
func TestSentinelConfigGood(t *testing.T) {
opts, err := processOptions(Options{
SentinelAddrs: "localhost:26379,localhost:46379",
RedisMasterName: "123",
ProcessID: "1",
PollInterval: time.Second,
})
assert.NoError(t, err)
assert.Equal(t, "FailoverClient", opts.client.Options().Addr)
assert.Nil(t, opts.client.Options().TLSConfig)
}
func TestSentinelConfigGoodTLS(t *testing.T) {
opts, err := processOptions(Options{
SentinelAddrs: "localhost:26379,localhost:46379",
RedisMasterName: "123",
ProcessID: "1",
PollInterval: time.Second,
RedisTLSConfig: &tls.Config{ServerName: "test_tls"},
})
assert.NoError(t, err)
assert.Equal(t, "FailoverClient", opts.client.Options().Addr)
assert.NotNil(t, opts.client.Options().TLSConfig)
assert.Equal(t, "test_tls", opts.client.Options().TLSConfig.ServerName)
}
func TestSentinelConfigNoMaster(t *testing.T) {
_, err := processOptions(Options{
SentinelAddrs: "localhost:26379,localhost:46379",
ProcessID: "1",
PollInterval: time.Second,
})
assert.Error(t, err)
}