-
Notifications
You must be signed in to change notification settings - Fork 0
/
nscache_test.go
60 lines (55 loc) · 1.43 KB
/
nscache_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
package nscache
import (
"errors"
"testing"
)
func TestNewCache(t *testing.T) {
driverName := "testcache"
conn := driverName + ":"
Register(driverName, mockFactory)
testCases := []struct {
conn string
valid bool
}{
{conn, true},
{"invalid", false},
{"invalid_conn:", false},
{"invalid+", false},
}
for _, tc := range testCases {
t.Run(tc.conn, func(t *testing.T) {
_, err := NewCache(tc.conn)
if tc.valid && err != nil {
t.Errorf("init cache error, connection string=%s err=%v", tc.conn, err)
return
}
if !tc.valid && err == nil {
t.Errorf("init cache error, expect to get an error but get nil, connection string=%s err=%v", tc.conn, err)
return
}
if !tc.valid && errors.Is(err, errUnsupportedCacheDriver) {
t.Errorf("init cache error, get an unsupported error, connection string=%s err=%v", tc.conn, err)
return
}
})
}
}
func TestNewCache_Unsupported(t *testing.T) {
testCases := []struct {
conn string
}{
{"unsupported:"},
}
for _, tc := range testCases {
t.Run(tc.conn, func(t *testing.T) {
_, err := NewCache(tc.conn)
if err == nil {
t.Errorf("init cache error, expect to get an error but get nil, connection string=%s err=%v", tc.conn, err)
return
}
if !errors.Is(err, errUnsupportedCacheDriver) {
t.Errorf("init cache error, expect to get error =>%v, but get error => %v, connection string=%s", errUnsupportedCacheDriver, err, tc.conn)
}
})
}
}