forked from alicebob/miniredis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_server_test.go
119 lines (92 loc) · 2.29 KB
/
cmd_server_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
package miniredis
import (
"testing"
"time"
"github.com/gomodule/redigo/redis"
)
// Test DBSIZE, FLUSHDB, and FLUSHALL.
func TestCmdServer(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := redis.Dial("tcp", s.Addr())
ok(t, err)
// Set something
{
s.Set("aap", "niet")
s.Set("roos", "vuur")
s.DB(1).Set("noot", "mies")
}
{
n, err := redis.Int(c.Do("DBSIZE"))
ok(t, err)
equals(t, 2, n)
b, err := redis.String(c.Do("FLUSHDB"))
ok(t, err)
equals(t, "OK", b)
n, err = redis.Int(c.Do("DBSIZE"))
ok(t, err)
equals(t, 0, n)
_, err = c.Do("SELECT", 1)
ok(t, err)
n, err = redis.Int(c.Do("DBSIZE"))
ok(t, err)
equals(t, 1, n)
b, err = redis.String(c.Do("FLUSHALL"))
ok(t, err)
equals(t, "OK", b)
n, err = redis.Int(c.Do("DBSIZE"))
ok(t, err)
equals(t, 0, n)
_, err = c.Do("SELECT", 4)
ok(t, err)
n, err = redis.Int(c.Do("DBSIZE"))
ok(t, err)
equals(t, 0, n)
}
{
b, err := redis.String(c.Do("FLUSHDB", "ASYNC"))
ok(t, err)
equals(t, "OK", b)
b, err = redis.String(c.Do("FLUSHALL", "ASYNC"))
ok(t, err)
equals(t, "OK", b)
}
{
_, err := redis.Int(c.Do("DBSIZE", "FOO"))
assert(t, err != nil, "no DBSIZE error")
_, err = redis.Int(c.Do("FLUSHDB", "FOO"))
assert(t, err != nil, "no FLUSHDB error")
_, err = redis.Int(c.Do("FLUSHDB", "ASYNC", "FOO"))
assert(t, err != nil, "no FLUSHDB error")
_, err = redis.Int(c.Do("FLUSHALL", "FOO"))
assert(t, err != nil, "no FLUSHALL error")
_, err = redis.Int(c.Do("FLUSHALL", "ASYNC", "FOO"))
assert(t, err != nil, "no FLUSHALL error")
_, err = redis.Int(c.Do("FLUSHALL", "ASYNC", "ASYNC"))
assert(t, err != nil, "no FLUSHALL error")
}
}
// Test TIME
func TestCmdServerTime(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := redis.Dial("tcp", s.Addr())
ok(t, err)
var seconds, microseconds int
res, err := redis.Values(c.Do("TIME"))
ok(t, err)
_, err = redis.Scan(res, &seconds, µseconds)
ok(t, err)
assert(t, seconds > 0, "seconds")
s.SetTime(time.Unix(100, 123456789))
res, err = redis.Values(c.Do("TIME"))
ok(t, err)
_, err = redis.Scan(res, &seconds, µseconds)
ok(t, err)
equals(t, seconds, 100)
equals(t, microseconds, 123456)
_, err = redis.MultiBulk(c.Do("TIME", "FOO"))
assert(t, err != nil, "no TIME error")
}