mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-03 00:38:40 +08:00
chore: add more tests (#3294)
This commit is contained in:
parent
3726851c7f
commit
28d3905731
@ -179,7 +179,7 @@ func TestRotateLoggerWithSizeLimitRotateRuleClose(t *testing.T) {
|
|||||||
}
|
}
|
||||||
logger, err := NewLogger(filename, new(SizeLimitRotateRule), false)
|
logger, err := NewLogger(filename, new(SizeLimitRotateRule), false)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Nil(t, logger.Close())
|
_ = logger.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRotateLoggerGetBackupWithSizeLimitRotateRuleFilename(t *testing.T) {
|
func TestRotateLoggerGetBackupWithSizeLimitRotateRuleFilename(t *testing.T) {
|
||||||
|
@ -214,13 +214,14 @@ func (cc CachedConn) SetCacheCtx(ctx context.Context, key string, val any) error
|
|||||||
return cc.cache.SetCtx(ctx, key, val)
|
return cc.cache.SetCtx(ctx, key, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCache sets v into cache with given key, using given expire.
|
// SetCacheWithExpire sets v into cache with given key with given expire.
|
||||||
func (cc CachedConn) SetCacheWithExpire(key string, val any, expire time.Duration) error {
|
func (cc CachedConn) SetCacheWithExpire(key string, val any, expire time.Duration) error {
|
||||||
return cc.SetCacheWithExpireCtx(context.Background(), key, val, expire)
|
return cc.SetCacheWithExpireCtx(context.Background(), key, val, expire)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCacheCtx sets v into cache with given key, using given expire.
|
// SetCacheWithExpireCtx sets v into cache with given key with given expire.
|
||||||
func (cc CachedConn) SetCacheWithExpireCtx(ctx context.Context, key string, val any, expire time.Duration) error {
|
func (cc CachedConn) SetCacheWithExpireCtx(ctx context.Context, key string, val any,
|
||||||
|
expire time.Duration) error {
|
||||||
return cc.cache.SetWithExpireCtx(ctx, key, val, expire)
|
return cc.cache.SetWithExpireCtx(ctx, key, val, expire)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,6 +498,29 @@ func TestCachedConnExecDropCache(t *testing.T) {
|
|||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCachedConn_SetCacheWithExpire(t *testing.T) {
|
||||||
|
r, err := miniredis.Run()
|
||||||
|
assert.Nil(t, err)
|
||||||
|
defer fx.DoWithTimeout(func() error {
|
||||||
|
r.Close()
|
||||||
|
return nil
|
||||||
|
}, time.Second)
|
||||||
|
|
||||||
|
const (
|
||||||
|
key = "user"
|
||||||
|
value = "any"
|
||||||
|
)
|
||||||
|
var conn trackedConn
|
||||||
|
c := NewNodeConn(&conn, redis.New(r.Addr()), cache.WithExpiry(time.Second*30))
|
||||||
|
assert.Nil(t, c.SetCacheWithExpire(key, value, time.Minute))
|
||||||
|
val, err := r.Get(key)
|
||||||
|
if assert.NoError(t, err) {
|
||||||
|
ttl := r.TTL(key)
|
||||||
|
assert.True(t, ttl > 0 && ttl <= time.Minute)
|
||||||
|
assert.Equal(t, fmt.Sprintf("%q", value), val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCachedConnExecDropCacheFailed(t *testing.T) {
|
func TestCachedConnExecDropCacheFailed(t *testing.T) {
|
||||||
const key = "user"
|
const key = "user"
|
||||||
var conn trackedConn
|
var conn trackedConn
|
||||||
|
Loading…
Reference in New Issue
Block a user