-
Notifications
You must be signed in to change notification settings - Fork 0
/
nn_cache_test.go
35 lines (32 loc) · 1016 Bytes
/
nn_cache_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
package nncache
import (
"github.com/bmizerany/assert"
"testing"
"time"
)
func TestNewNNCache1(t *testing.T) {
cache, _ := NewNNCache(DefaultConfig(10 * time.Minute))
err := cache.Set("luwenchao", []byte("zhendishuai"))
assert.Equal(t, err, nil)
res, err := cache.Get("luwenchao")
assert.Equal(t, err, nil)
assert.Equal(t, res, []byte("zhendishuai"))
}
func TestNewNNCache2(t *testing.T) {
cache, _ := NewNNCache(DefaultConfig(10 * time.Minute))
err := cache.Set("luwenchao", []byte("zhendishuai"))
assert.Equal(t, err, nil)
res, err := cache.Get("someting")
assert.Equal(t, string(res), "")
assert.Equal(t, err.Error(), "Entry not found")
}
func TestNewNNCache3(t *testing.T) {
cache, _ := NewNNCache(DefaultConfig(10 * time.Minute))
err := cache.Set("luwenchao", []byte("zhendishuai"))
assert.Equal(t, err, nil)
err = cache.Delete("luwenchao")
assert.Equal(t, err, nil)
res, err := cache.Get("luwenchao")
assert.Equal(t, string(res), "")
assert.Equal(t, err.Error(), "Entry not found")
}