-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_connection_test.go
87 lines (68 loc) · 1.98 KB
/
cmd_connection_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
package redisson
import (
"context"
. "github.com/smartystreets/goconvey/convey"
"testing"
"time"
)
func testClientID(ctx context.Context, c Cmdable) []string {
cc := c.ClientID(ctx)
So(cc.Err(), ShouldBeNil)
So(cc.Val(), ShouldBeGreaterThan, 0)
return nil
}
func testClientKill(ctx context.Context, c Cmdable) []string {
r := c.ClientKill(ctx, "1.1.1.1:1111")
So(r.Err(), ShouldNotBeNil)
So(r.Err().Error(), ShouldContainSubstring, "No such client")
return nil
}
func testClientKillByFilter(ctx context.Context, c Cmdable) []string {
r := c.ClientKillByFilter(ctx, "TYPE", "test")
So(r.Err(), ShouldNotBeNil)
So(r.Err().Error(), ShouldContainSubstring, "Unknown client type 'test'")
return nil
}
func testClientList(ctx context.Context, c Cmdable) []string {
clientList := c.ClientList(ctx)
So(clientList.Err(), ShouldBeNil)
So(len(clientList.Val()), ShouldBeGreaterThan, 0)
return nil
}
func testClientPause(ctx context.Context, c Cmdable) []string {
err := c.ClientPause(ctx, time.Second).Err()
So(err, ShouldBeNil)
start := time.Now()
err = c.Ping(ctx).Err()
So(err, ShouldBeNil)
So(time.Now(), ShouldNotEqual, start.Add(time.Second))
return nil
}
func testEcho(ctx context.Context, c Cmdable) []string {
echo := c.Echo(ctx, "hello")
So(echo.Err(), ShouldBeNil)
So(echo.Val(), ShouldEqual, "hello")
return nil
}
func testPing(ctx context.Context, c Cmdable) []string {
echo := c.Ping(ctx)
So(echo.Err(), ShouldBeNil)
So(echo.Val(), ShouldEqual, "PONG")
return nil
}
func testQuit(_ context.Context, _ Cmdable) []string {
return nil
}
func connectionTestUnits() []TestUnit {
return []TestUnit{
{CommandClientID, testClientID},
{CommandClientKill, testClientKill},
{CommandClientKillByFilter, testClientKillByFilter},
{CommandClientList, testClientList},
{CommandClientPause, testClientPause},
{CommandEcho, testEcho},
{CommandPing, testPing},
{CommandQuit, testQuit},
}
}
func TestClient_Connection(t *testing.T) { doTestUnits(t, connectionTestUnits) }