-
Notifications
You must be signed in to change notification settings - Fork 0
/
store_test.go
88 lines (76 loc) · 1.22 KB
/
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
// +build unit
package cache
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestStore_Add(t *testing.T) {
s := Store{
items: make(map[string]*Item),
}
cases := []struct {
name string
key string
input interface{}
}{
{
name: "string",
key: "foo",
input: "bar",
},
{
name: "int",
key: "foo-int",
input: 1,
},
{
name: "bool",
key: "foo-bool",
input: true,
},
{
name: "struct",
key: "foo-struct",
input: struct {
name string
}{
name: "Foo",
},
},
{
name: "float",
key: "foo-float",
input: float32(0.55),
},
}
for _, tc := range cases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
s.Add(tc.key, tc.input)
s.mu.RLock()
assert.NotNil(t, s.items[tc.key])
assert.Equal(t, &Item{data: tc.input}, s.items[tc.key])
s.mu.RUnlock()
})
}
}
func TestStore_Get(t *testing.T) {
s := &Store{
items: make(map[string]*Item),
}
s.Add("foo", "bar")
i := s.Get("foo")
assert.NotNil(t, i)
}
func TestStore_Delete(t *testing.T) {
s := &Store{
items: make(map[string]*Item),
}
s.Add("foo", "bar")
i := s.Get("foo")
assert.NotNil(t, i)
s.Delete("foo")
i = s.Get("foo")
assert.Nil(t, i)
}