-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsentinel_test.go
67 lines (58 loc) · 1.48 KB
/
sentinel_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 minisentinel
import (
"testing"
"github.com/alicebob/miniredis/v2"
"github.com/matryer/is"
"github.com/gomodule/redigo/redis"
)
func TestNewSentinel(t *testing.T) {
is := is.New(t)
m, err := miniredis.Run()
is.NoErr(err)
defer m.Close()
s := NewSentinel(m, WithReplica(m))
is.Equal(s.Master(), m) // make sure the master is correctly set
is.Equal(s.Replica(), m) // make sure the replicas are correctly set
err = s.Start()
is.NoErr(err)
defer s.Close()
c, err := redis.Dial("tcp", s.Addr())
is.NoErr(err)
// just running all the commands... not really testing expected results (see specifc unit tests for that)
// PING command
{
v, err := redis.String(c.Do("PING"))
is.NoErr(err)
t.Log(v)
}
// MASTERS command
{
// results is an []interfaces which points to [][]strings
results, err := c.Do("SENTINEL", "MASTERS")
is.NoErr(err)
info, err := redis.Strings(results.([]interface{})[0], nil)
t.Log("MASTERS response:")
t.Logf("%v", info)
for _, v := range info {
t.Logf("%v", v)
}
}
// GET-MASTER-ADDR-BY-NAME command
{
results, err := redis.Strings(c.Do("SENTINEL", "GET-MASTER-ADDR-BY-NAME", "MYMASTER"))
is.NoErr(err)
t.Log(results)
}
// SLAVES command
{
// results is an []interfaces which points to [][]strings
results, err := c.Do("SENTINEL", "SLAVES")
is.NoErr(err)
info, err := redis.Strings(results.([]interface{})[0], nil)
t.Log("SLAVES response:")
t.Logf("%v", info)
for _, v := range info {
t.Logf("%v", v)
}
}
}