-
Notifications
You must be signed in to change notification settings - Fork 5
/
caching_store_test.go
65 lines (51 loc) · 1.48 KB
/
caching_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
package gbox
import (
"net/url"
"testing"
"github.com/stretchr/testify/require"
)
func TestNewCachingStore(t *testing.T) {
testCases := map[string]struct {
url string
expectedErrorMsg string
}{
"redis": {
url: "redis://redis",
},
"freecache": {
url: "freecache://?cache_size=1024",
},
"unknown": {
url: "unknown://unknown",
expectedErrorMsg: "caching store schema: unknown is not support",
},
}
for name, testCase := range testCases {
u, _ := url.Parse(testCase.url)
_, err := NewCachingStore(u)
if testCase.expectedErrorMsg == "" {
require.NoErrorf(t, err, "case %s: unexpected error", name)
} else {
require.Errorf(t, err, "case %s: should be error", name)
require.Equalf(t, testCase.expectedErrorMsg, err.Error(), "case %s: unexpected error message", name)
}
}
}
func TestFreeCacheStoreFactory(t *testing.T) {
u, _ := url.Parse("freecache://?cache_size=1024")
_, e := FreeCacheStoreFactory(u)
require.NoError(t, e)
u, _ = url.Parse("freecache://") // missing cache size
_, e = NewCachingStore(u)
require.Error(t, e)
require.Equal(t, "cache_size must be set explicit", e.Error())
}
func TestRedisCachingStoreFactory(t *testing.T) {
u, _ := url.Parse("redis://redis")
_, e := RedisCachingStoreFactory(u)
require.NoError(t, e)
u, _ = url.Parse("redis://redis?db=xyz")
_, e = RedisCachingStoreFactory(u)
require.Error(t, e)
require.Equal(t, "`db` param should be numeric string, xyz given", e.Error())
}