-
Notifications
You must be signed in to change notification settings - Fork 0
/
redisstore_test.go
62 lines (51 loc) · 1.14 KB
/
redisstore_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
package sessions
import (
"os"
"reflect"
"testing"
"gopkg.in/redis.v5"
)
//NOTE: tests in this file will user the REDISADDR
//environment variable for the redis server address.
//If not defined, it will default to a local instance of redis.
//To start a local redis server using Docker, run
//this command:
// docker run -d -p 6379:6379 redis
func TestRedisStore(t *testing.T) {
type State struct {
Requests int
}
sid, err := NewSessionID(testSigningKey)
if nil != err {
t.Fatal(err)
}
redisAddr := os.Getenv("REDISADDR")
if len(redisAddr) == 0 {
redisAddr = "127.0.0.1:6379"
}
client := redis.NewClient(&redis.Options{
Addr: redisAddr,
})
redisStore := NewRedisStore(client, -1)
state1 := &State{
Requests: 100,
}
err = redisStore.Save(sid, state1)
if nil != err {
t.Fatal(err)
}
state2 := &State{}
err = redisStore.Get(sid, state2)
if nil != err {
t.Fatal(err)
}
if !reflect.DeepEqual(state1, state2) {
t.Fatalf("Retrieved state did not match.\n got %v \n expected %v", state2, state1)
}
redisStore.Delete(sid)
state3 := &State{}
err = redisStore.Get(sid, state3)
if ErrStateNotFound != err {
t.Fatal(err)
}
}