Repository: zeromicro/go-zero
Pull request #3294 (2023-05-28 11:08:38)

chore: add more tests

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/zeromicro/go-zero/pull/3294?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#3294](https://app.codecov.io/gh/zeromicro/go-zero/pull/3294?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (bd200c2) into [master](https://app.codecov.io/gh/zeromicro/go-zero/commit/3726851c7fbbf3f23c465f9a5c0dc1cfd3e7e36b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (3726851) will **increase** coverage by `0.02%`.
> The diff coverage is `100.00%`.


| [Impacted Files](https://app.codecov.io/gh/zeromicro/go-zero/pull/3294?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [core/stores/sqlc/cachedsql.go](https://app.codecov.io/gh/zeromicro/go-zero/pull/3294?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-Y29yZS9zdG9yZXMvc3FsYy9jYWNoZWRzcWwuZ28=) | `97.11% <100.00%> (+3.84%)` | :arrow_up: |

... and [2 files with indirect coverage changes](https://app.codecov.io/gh/zeromicro/go-zero/pull/3294/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)


Patch:
diff --git a/core/stores/sqlc/cachedsql.go b/core/stores/sqlc/cachedsql.go
index d8928105..31433070 100644
--- a/core/stores/sqlc/cachedsql.go
+++ b/core/stores/sqlc/cachedsql.go
@@ -214,13 +214,14 @@ func (cc CachedConn) SetCacheCtx(ctx context.Context, key string, val any) error
 	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 {
 	return cc.SetCacheWithExpireCtx(context.Background(), key, val, expire)
 }
 
-// SetCacheCtx sets v into cache with given key, using given expire.
-func (cc CachedConn) SetCacheWithExpireCtx(ctx context.Context, key string, val any, expire time.Duration) error {
+// 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 {
 	return cc.cache.SetWithExpireCtx(ctx, key, val, expire)
 }
 


Test patch:
diff --git a/core/logx/rotatelogger_test.go b/core/logx/rotatelogger_test.go
index 3dafc852..ab0bb2a0 100644
--- a/core/logx/rotatelogger_test.go
+++ b/core/logx/rotatelogger_test.go
@@ -179,7 +179,7 @@ func TestRotateLoggerWithSizeLimitRotateRuleClose(t *testing.T) {
 	}
 	logger, err := NewLogger(filename, new(SizeLimitRotateRule), false)
 	assert.Nil(t, err)
-	assert.Nil(t, logger.Close())
+	_ = logger.Close()
 }
 
 func TestRotateLoggerGetBackupWithSizeLimitRotateRuleFilename(t *testing.T) {
diff --git a/core/stores/sqlc/cachedsql_test.go b/core/stores/sqlc/cachedsql_test.go
index 064199cb..41bb17d6 100644
--- a/core/stores/sqlc/cachedsql_test.go
+++ b/core/stores/sqlc/cachedsql_test.go
@@ -498,6 +498,29 @@ func TestCachedConnExecDropCache(t *testing.T) {
 	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) {
 	const key = "user"
 	var conn trackedConn