Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e69b905

Browse files
kevwanxiandong-italki
authored andcommittedJun 14, 2023
chore: add more tests (zeromicro#3294)
1 parent f0856e1 commit e69b905

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed
 

‎core/logx/rotatelogger_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func TestRotateLoggerWithSizeLimitRotateRuleClose(t *testing.T) {
179179
}
180180
logger, err := NewLogger(filename, new(SizeLimitRotateRule), false)
181181
assert.Nil(t, err)
182-
assert.Nil(t, logger.Close())
182+
_ = logger.Close()
183183
}
184184

185185
func TestRotateLoggerGetBackupWithSizeLimitRotateRuleFilename(t *testing.T) {

‎core/stores/sqlc/cachedsql.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,14 @@ func (cc CachedConn) SetCacheCtx(ctx context.Context, key string, val any) error
214214
return cc.cache.SetCtx(ctx, key, val)
215215
}
216216

217-
// SetCache sets v into cache with given key, using given expire.
217+
// SetCacheWithExpire sets v into cache with given key with given expire.
218218
func (cc CachedConn) SetCacheWithExpire(key string, val any, expire time.Duration) error {
219219
return cc.SetCacheWithExpireCtx(context.Background(), key, val, expire)
220220
}
221221

222-
// SetCacheCtx sets v into cache with given key, using given expire.
223-
func (cc CachedConn) SetCacheWithExpireCtx(ctx context.Context, key string, val any, expire time.Duration) error {
222+
// SetCacheWithExpireCtx sets v into cache with given key with given expire.
223+
func (cc CachedConn) SetCacheWithExpireCtx(ctx context.Context, key string, val any,
224+
expire time.Duration) error {
224225
return cc.cache.SetWithExpireCtx(ctx, key, val, expire)
225226
}
226227

‎core/stores/sqlc/cachedsql_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,29 @@ func TestCachedConnExecDropCache(t *testing.T) {
498498
assert.NotNil(t, err)
499499
}
500500

501+
func TestCachedConn_SetCacheWithExpire(t *testing.T) {
502+
r, err := miniredis.Run()
503+
assert.Nil(t, err)
504+
defer fx.DoWithTimeout(func() error {
505+
r.Close()
506+
return nil
507+
}, time.Second)
508+
509+
const (
510+
key = "user"
511+
value = "any"
512+
)
513+
var conn trackedConn
514+
c := NewNodeConn(&conn, redis.New(r.Addr()), cache.WithExpiry(time.Second*30))
515+
assert.Nil(t, c.SetCacheWithExpire(key, value, time.Minute))
516+
val, err := r.Get(key)
517+
if assert.NoError(t, err) {
518+
ttl := r.TTL(key)
519+
assert.True(t, ttl > 0 && ttl <= time.Minute)
520+
assert.Equal(t, fmt.Sprintf("%q", value), val)
521+
}
522+
}
523+
501524
func TestCachedConnExecDropCacheFailed(t *testing.T) {
502525
const key = "user"
503526
var conn trackedConn

0 commit comments

Comments
 (0)
Please sign in to comment.