-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory_test.go
74 lines (57 loc) · 1.42 KB
/
memory_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
package session
import (
"container/list"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
func TestSessionMemoryProvider(t *testing.T) {
provider := &MemoryProvider{
list: list.New(),
data: make(map[string]*list.Element),
}
provider.Init(3, MemoryOptions{
BytesLimit: 50,
})
Convey("exist", t, func() {
So(provider.Exist("foo"), ShouldBeFalse)
})
Convey("read exists", t, func() {
data := make(map[interface{}]interface{})
data["a"] = "b"
provider.Write("fooOOOOO", data)
session, err := provider.Read("fooOOOOO")
So(err, ShouldBeNil)
So(session, ShouldNotBeNil)
provider.Destroy("fooOOOOO")
})
Convey("read not exists", t, func() {
session, err := provider.Read("fooOOOOO")
So(err, ShouldBeNil)
So(session, ShouldNotBeNil)
})
Convey("write", t, func() {
Convey("ok", func() {
data := make(map[interface{}]interface{})
data["a"] = "b"
So(provider.Write("foo", data), ShouldBeNil)
})
Convey("size limit", func() {
data := make(map[interface{}]interface{})
data["a"] = string(randString(1000))
So(provider.Write("foo", data), ShouldNotBeNil)
})
})
Convey("destroy", t, func() {
So(provider.Destroy("foo"), ShouldBeNil)
})
Convey("gc", t, func() {
data := make(map[interface{}]interface{})
data["a"] = "b"
provider.Write("first", data)
time.Sleep(time.Second * 4)
data["a"] = "b"
provider.Write("second", data)
provider.GC()
})
}