fix golint issues in core/collection, refine cache interface (#475)

This commit is contained in:
Kevin Wan
2021-02-18 15:49:56 +08:00
committed by GitHub
parent f14ab70035
commit 457048bfac
14 changed files with 139 additions and 89 deletions

View File

@@ -39,14 +39,14 @@ func TestCacheNode_DelCache(t *testing.T) {
stat: NewCacheStat("any"),
errNotFound: errTestNotFound,
}
assert.Nil(t, cn.DelCache())
assert.Nil(t, cn.DelCache([]string{}...))
assert.Nil(t, cn.DelCache(make([]string, 0)...))
cn.SetCache("first", "one")
assert.Nil(t, cn.DelCache("first"))
cn.SetCache("first", "one")
cn.SetCache("second", "two")
assert.Nil(t, cn.DelCache("first", "second"))
assert.Nil(t, cn.Del())
assert.Nil(t, cn.Del([]string{}...))
assert.Nil(t, cn.Del(make([]string, 0)...))
cn.Set("first", "one")
assert.Nil(t, cn.Del("first"))
cn.Set("first", "one")
cn.Set("second", "two")
assert.Nil(t, cn.Del("first", "second"))
}
func TestCacheNode_InvalidCache(t *testing.T) {
@@ -64,7 +64,7 @@ func TestCacheNode_InvalidCache(t *testing.T) {
}
s.Set("any", "value")
var str string
assert.NotNil(t, cn.GetCache("any", &str))
assert.NotNil(t, cn.Get("any", &str))
assert.Equal(t, "", str)
_, err = s.Get("any")
assert.Equal(t, miniredis.ErrKeyNotFound, err)
@@ -91,7 +91,7 @@ func TestCacheNode_Take(t *testing.T) {
})
assert.Nil(t, err)
assert.Equal(t, "value", str)
assert.Nil(t, cn.GetCache("any", &str))
assert.Nil(t, cn.Get("any", &str))
val, err := store.Get("any")
assert.Nil(t, err)
assert.Equal(t, `"value"`, val)
@@ -116,7 +116,7 @@ func TestCacheNode_TakeNotFound(t *testing.T) {
return errTestNotFound
})
assert.True(t, cn.IsNotFound(err))
assert.True(t, cn.IsNotFound(cn.GetCache("any", &str)))
assert.True(t, cn.IsNotFound(cn.Get("any", &str)))
val, err := store.Get("any")
assert.Nil(t, err)
assert.Equal(t, `*`, val)
@@ -126,7 +126,7 @@ func TestCacheNode_TakeNotFound(t *testing.T) {
return nil
})
assert.True(t, cn.IsNotFound(err))
assert.True(t, cn.IsNotFound(cn.GetCache("any", &str)))
assert.True(t, cn.IsNotFound(cn.Get("any", &str)))
store.Del("any")
var errDummy = errors.New("dummy")
@@ -157,7 +157,7 @@ func TestCacheNode_TakeWithExpire(t *testing.T) {
})
assert.Nil(t, err)
assert.Equal(t, "value", str)
assert.Nil(t, cn.GetCache("any", &str))
assert.Nil(t, cn.Get("any", &str))
val, err := store.Get("any")
assert.Nil(t, err)
assert.Equal(t, `"value"`, val)
@@ -200,8 +200,8 @@ func TestCacheValueWithBigInt(t *testing.T) {
value int64 = 323427211229009810
)
assert.Nil(t, cn.SetCache(key, value))
assert.Nil(t, cn.Set(key, value))
var val interface{}
assert.Nil(t, cn.GetCache(key, &val))
assert.Nil(t, cn.Get(key, &val))
assert.Equal(t, strconv.FormatInt(value, 10), fmt.Sprintf("%v", val))
}