-
Notifications
You must be signed in to change notification settings - Fork 17
/
list_test.go
64 lines (50 loc) · 1.37 KB
/
list_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
package redis
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestLPushCommand(t *testing.T) {
i, err := c.LPush("lpushkey", "va").Result()
assert.NoError(t, err)
assert.Equal(t, int64(1), i)
i, err = c.LPush("lpushkey", "vb").Result()
assert.NoError(t, err)
assert.Equal(t, int64(2), i)
i, err = c.LPush("lpushkey", "vc", "vd").Result()
assert.NoError(t, err)
assert.Equal(t, int64(4), i)
i, err = c.LPush("lpushkey2", "1", "2").Result()
assert.NoError(t, err)
assert.Equal(t, int64(2), i)
i, err = c.LPush("lpush3key").Result()
assert.Error(t, err)
}
func TestLPopCommand(t *testing.T) {
s, err := c.LPop("lpop1").Result()
assert.Zero(t, s)
assert.Error(t, err)
i, err := c.LPush("list", "a", "b").Result()
assert.NoError(t, err)
assert.Equal(t, int64(2), i)
s, err = c.LPop("list").Result()
assert.NoError(t, err)
assert.Equal(t, "b", s)
s, err = c.LPop("list").Result()
assert.NoError(t, err)
assert.Equal(t, "a", s)
s, err = c.LPop("list").Result()
assert.Error(t, err)
assert.Zero(t, s)
}
func TestLRangeCommand(t *testing.T) {
s, err := c.LRange("lrange", 0, 0).Result()
assert.Error(t, err)
assert.Zero(t, s)
sl, err := c.Set("works", "esfkjsefj", 0).Result()
assert.NoError(t, err)
assert.NotZero(t, sl)
assert.NotEmpty(t, sl)
i, err := c.LPush("list2", "a", "b").Result()
assert.NoError(t, err)
assert.Equal(t, int64(2), i)
}