-
Notifications
You must be signed in to change notification settings - Fork 0
/
etcd_session_store_test.go
91 lines (68 loc) · 1.71 KB
/
etcd_session_store_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
package casstore
import (
"context"
"testing"
"github.com/stretchr/testify/require"
clientv3 "go.etcd.io/etcd/client/v3"
"gopkg.in/cas.v2"
)
var (
store cas.SessionStore
_defaultEtcd = "http://127.0.0.1:2379"
)
func init() {
store, _ = NewEtcdSessionStore(clientv3.Config{Endpoints: []string{_defaultEtcd}},
context.Background(), "/cas/sessions", 3600)
}
func TestSessionStore_Get(t *testing.T) {
v, ok := store.Get("key1")
require.False(t, ok)
require.Equal(t, "", v)
err := store.Set("key1", "value1")
require.Nil(t, err)
v, ok = store.Get("key1")
require.True(t, ok)
require.Equal(t, "value1", v)
}
func TestSessionStore_Set(t *testing.T) {
err := store.Set("key1", "value1")
require.Nil(t, err)
err = store.Set("key2", "value2")
require.Nil(t, err)
v, ok := store.Get("key1")
require.True(t, ok)
require.Equal(t, "value1", v)
v, ok = store.Get("key2")
require.True(t, ok)
require.Equal(t, "value2", v)
err = store.Set("key2", "value2-new")
require.Nil(t, err)
v, ok = store.Get("key2")
require.True(t, ok)
require.Equal(t, "value2-new", v)
}
func TestSessionStore_Delete(t *testing.T) {
err := store.Set("key1", "value1")
require.Nil(t, err)
err = store.Set("key2", "value2")
require.Nil(t, err)
v, ok := store.Get("key1")
require.True(t, ok)
require.Equal(t, "value1", v)
v, ok = store.Get("key2")
require.True(t, ok)
require.Equal(t, "value2", v)
err = store.Delete("key2")
require.Nil(t, err)
v, ok = store.Get("key1")
require.True(t, ok)
require.Equal(t, "value1", v)
v, ok = store.Get("key2")
require.False(t, ok)
require.Equal(t, "", v)
err = store.Delete("key1")
require.Nil(t, err)
v, ok = store.Get("key1")
require.False(t, ok)
require.Equal(t, "", v)
}