-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredis_test.go
67 lines (58 loc) · 1.35 KB
/
redis_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 redisstore
import (
"testing"
"github.com/alicebob/miniredis"
"github.com/stretchr/testify/assert"
"github.com/webx-top/echo/defaults"
ss "github.com/webx-top/echo/middleware/session/engine"
)
func testConnect(addr string) {
redisOptions := &RedisOptions{
Size: 10,
Network: `tcp`,
Address: addr,
Password: ``,
DB: 0,
KeyPairs: [][]byte{
[]byte(`12345678901234567890123456789012`),
[]byte(`12345678901234567890123456789012`),
},
MaxAge: 86400,
MaxReconnect: 30,
}
RegWithOptions(redisOptions)
}
func TestReconnect(t *testing.T) {
s, err := miniredis.Run()
if err != nil {
panic(err)
}
defer s.Close()
testConnect(s.Addr())
store := ss.Get(`redis`)
ctx := defaults.NewMockContext()
sess, err := store.New(ctx, `TEST_REDIS_SID`)
assert.NoError(t, err)
sess.AddFlash(`TEST1`)
err = store.Save(ctx, sess)
assert.NoError(t, err)
sess2, err := store.Get(ctx, `TEST_REDIS_SID`)
assert.NoError(t, err)
t.Logf(`%+v`, sess.Values)
t.Logf(`%+v`, sess2.Values)
}
func TestReconnect2(t *testing.T) {
s, err := miniredis.Run()
if err != nil {
panic(err)
}
defer s.Close()
testConnect(s.Addr())
store := ss.Get(`redis`)
ctx := defaults.NewMockContext()
sess, err := store.New(ctx, `TEST_REDIS_SID`)
assert.NoError(t, err)
sess.AddFlash(`TEST2`)
err = store.Save(ctx, sess)
assert.NoError(t, err)
}