-
-
Notifications
You must be signed in to change notification settings - Fork 93
/
redis_shard_test.go
51 lines (41 loc) · 1.67 KB
/
redis_shard_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
package centrifuge
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestRedisShard_ConfFromAddress(t *testing.T) {
conf, err := confFromAddress("127.0.0.1:6379", RedisShardConfig{})
require.NoError(t, err)
require.Equal(t, "tcp", conf.network)
require.Equal(t, "127.0.0.1:6379", conf.address)
conf, err = confFromAddress("localhost:6379", RedisShardConfig{})
require.NoError(t, err)
require.Equal(t, "tcp", conf.network)
require.Equal(t, "localhost:6379", conf.address)
_, err = confFromAddress("localhost:", RedisShardConfig{})
require.Error(t, err)
conf, err = confFromAddress("tcp://localhost:6379", RedisShardConfig{})
require.NoError(t, err)
require.Equal(t, "tcp", conf.network)
require.Equal(t, "localhost:6379", conf.address)
conf, err = confFromAddress("tcp://:pass@localhost:6379", RedisShardConfig{})
require.NoError(t, err)
require.Equal(t, "tcp", conf.network)
require.Equal(t, "localhost:6379", conf.address)
require.Equal(t, 0, conf.DB)
require.Equal(t, "pass", conf.Password)
conf, err = confFromAddress("tcp://localhost:6379/9", RedisShardConfig{})
require.NoError(t, err)
require.Equal(t, "tcp", conf.network)
require.Equal(t, "localhost:6379", conf.address)
require.Equal(t, 9, conf.DB)
require.Equal(t, "", conf.Password)
_, err = confFromAddress("tcp://localhost:6379/not_a_number", RedisShardConfig{})
require.Error(t, err)
conf, err = confFromAddress("unix://:pass@/var/run/tarantool/my_instance.sock", RedisShardConfig{})
require.NoError(t, err)
require.Equal(t, "unix", conf.network)
require.Equal(t, "/var/run/tarantool/my_instance.sock", conf.address)
require.Equal(t, 0, conf.DB)
require.Equal(t, "pass", conf.Password)
}