-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstores_test.go
91 lines (60 loc) · 1.36 KB
/
stores_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 sdbc
import (
"bytes"
"gotest.tools/v3/assert"
"testing"
"time"
)
func TestStoresGetInvalidAssert(t *testing.T) {
t.Parallel()
var pool bufPool
pool.Pool.Put("invalid type")
res := pool.Get()
assert.Check(t, res != nil)
assert.Check(t, bytes.Equal(res.Bytes(), []byte{}))
}
func TestRequestsUnknownKey(t *testing.T) {
t.Parallel()
var req requests
_, ok := req.get("unknown key")
assert.Check(t, !ok)
}
func TestRequestsInvalidTypeCast(t *testing.T) {
t.Parallel()
var req requests
req.store.Store("some_key", "invalid value")
_, ok := req.get("some_key")
assert.Check(t, !ok)
}
func TestRequestsReset(t *testing.T) {
t.Parallel()
var req requests
req.prepare()
req.store.Store("some_key", "invalid value")
assert.Equal(t, 2, req.len())
req.reset()
_, ok := req.get("some_key")
assert.Check(t, !ok)
assert.Equal(t, 0, req.len())
}
func TestLiveQueriesGetErrorCases(t *testing.T) {
t.Parallel()
var lq liveQueries
_, ok := lq.get("unknown_key", false)
assert.Check(t, !ok)
lq.store.Store("some_key", "invalid value")
_, ok = lq.get("some_key", false)
assert.Check(t, !ok)
}
func TestLiveQueriesDel(t *testing.T) {
t.Parallel()
var lq liveQueries
ch, ok := lq.get("some_key", true)
assert.Check(t, ok)
lq.del("some_key")
select {
case <-ch:
case <-time.After(1 * time.Second):
t.Fatal("channel not closed")
}
}