-
Notifications
You must be signed in to change notification settings - Fork 1
/
redis_connector_test.go
38 lines (32 loc) · 1.67 KB
/
redis_connector_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
package connect
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_applyRedisConnectionPoolOptions(t *testing.T) {
t.Run("option is nil", func(t *testing.T) {
option := applyRedisConnectionPoolOptions(nil)
// should return default values
assert.EqualValues(t, defaultRedisConnectionPoolOptions.PoolSize, option.PoolSize)
assert.EqualValues(t, defaultRedisConnectionPoolOptions.IdleCount, option.IdleCount)
assert.EqualValues(t, defaultRedisConnectionPoolOptions.IdleTimeout, option.IdleTimeout)
assert.EqualValues(t, defaultRedisConnectionPoolOptions.ReadTimeout, option.ReadTimeout)
assert.EqualValues(t, defaultRedisConnectionPoolOptions.WriteTimeout, option.WriteTimeout)
assert.EqualValues(t, defaultRedisConnectionPoolOptions.DialTimeout, option.DialTimeout)
assert.EqualValues(t, defaultRedisConnectionPoolOptions.MaxConnLifetime, option.MaxConnLifetime)
})
t.Run("merge struct", func(t *testing.T) {
option := applyRedisConnectionPoolOptions(&RedisConnectionPoolOptions{
WriteTimeout: 50,
ReadTimeout: 3,
})
// all should set to default values except for WriteTimeout and ReadTimeout
assert.EqualValues(t, defaultRedisConnectionPoolOptions.PoolSize, option.PoolSize)
assert.EqualValues(t, defaultRedisConnectionPoolOptions.IdleCount, option.IdleCount)
assert.EqualValues(t, defaultRedisConnectionPoolOptions.IdleTimeout, option.IdleTimeout)
assert.EqualValues(t, 3, option.ReadTimeout)
assert.EqualValues(t, 50, option.WriteTimeout)
assert.EqualValues(t, defaultRedisConnectionPoolOptions.DialTimeout, option.DialTimeout)
assert.EqualValues(t, defaultRedisConnectionPoolOptions.MaxConnLifetime, option.MaxConnLifetime)
})
}