-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfaststructcache_test.go
More file actions
48 lines (37 loc) · 894 Bytes
/
faststructcache_test.go
File metadata and controls
48 lines (37 loc) · 894 Bytes
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
package faststructcache
import (
"testing"
"github.com/zeebo/assert"
)
type TestKey struct {
Key string
}
type TestVal struct {
Number uint32
CopyOfKey TestKey
Value string
}
func TestCache(t *testing.T) {
c := New[TestKey, TestVal](32, false)
assert.NotNil(t, c)
testCache(c, t)
}
func TestCacheCompressed(t *testing.T) {
c := New[TestKey, TestVal](32, true)
assert.NotNil(t, c)
testCache(c, t)
}
func testCache(c FastStructCache[TestKey, TestVal], t *testing.T) {
key := TestKey{Key: "MyKeyString123"}
var nilVal *TestVal
val := TestVal{Number: 456, CopyOfKey: key, Value: "PMyValueString789"}
assert.Equal(t, c.Has(key), false)
assert.Equal(t, c.Get(key), nilVal)
c.Set(key, val)
assert.Equal(t, c.Has(key), true)
gotten := c.Get(key)
assert.Equal(t, *gotten, val)
c.Del(key)
assert.Equal(t, c.Get(key), nilVal)
assert.Equal(t, c.Has(key), false)
}