-
Notifications
You must be signed in to change notification settings - Fork 0
/
polacache_test.go
57 lines (42 loc) · 1.04 KB
/
polacache_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
package polacache
import (
"math/rand"
"strconv"
"testing"
"time"
"github.com/stretchr/testify/require"
)
var polacache = New(1 * time.Minute)
var testItem = Item{
Key: "polatest",
Value: "testifying polacache",
}
func TestPolacache_GetSet(t *testing.T) {
requires := require.New(t)
polacache.Set(testItem, time.Now().Add(1*time.Hour).Unix())
it, err := polacache.Get(testItem.Key)
requires.NoError(err)
requires.Equal(testItem.Value, it)
polacache.stopCleanup()
}
func TestPolacache_ErrorMessage(t *testing.T) {
requires := require.New(t)
polacache.Delete(testItem.Key)
it, err := polacache.Get(testItem.Key)
requires.EqualError(err, "key polatest not in cache")
requires.Equal(Item{}, it)
polacache.stopCleanup()
}
func BenchmarkPolacache(b *testing.B) {
rand.Seed(time.Now().UnixNano())
b.ResetTimer()
b.RunParallel(func(p *testing.PB) {
for p.Next() {
polacache.Set(Item{
Key: strconv.Itoa(int(rand.Int63())),
Value: "polacache test",
}, time.Now().Add(1*time.Hour).Unix())
}
})
polacache.stopCleanup()
}