Skip to content

Commit 4c9ec6d

Browse files
author
wubin48435
committed
test(caches): 增强缓存模块的测试覆盖率并优化反射处理
增加了对不同数据结构的测试用例,包括结构体切片、指针结构体切片、字典切片和指针字典切片。 同时优化了反射相关的代码,增加了对零值和无效值的检查,提高了代码的健壮性。 - 新增TestCaches_ease_WithStructSlice等多个测试用例 - 优化ease方法中的反射处理逻辑 - 简化了条件判断语句
1 parent 93ce395 commit 4c9ec6d

8 files changed

Lines changed: 387 additions & 51 deletions

File tree

.cursorignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# 忽略编译生成的文件
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
*.test
8+
*.out
9+
10+
# 忽略依赖目录
11+
vendor/
12+
13+
# 忽略Go工作区文件
14+
go.work
15+
go.work.sum
16+
17+
# 忽略环境文件
18+
.env
19+
20+
# 忽略IDE配置文件
21+
.idea/
22+
.vscode/
23+
24+
# 忽略Git相关文件
25+
.git/
26+
.gitignore
27+
28+
# 忽略测试相关文件
29+
_test/
30+
*.test
31+
32+
# 忽略缓存文件
33+
*.local
34+
.DS_Store
35+
36+
# 忽略生成的OpenAPI文件
37+
swaggerV2ToV3*
38+
39+
# 忽略临时文件
40+
*.tmp
41+
*.temp

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ go.work.sum
2323

2424
# env file
2525
.env
26+
.vscode/

.vscode/settings.json

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
{
2-
"vscode.tsc.compiler.alertTSConfigChanges": "never",
3-
"go.useLanguageServer": true,
4-
"go.toolsManagement.autoUpdate": true,
5-
"go.gopath": "/Users/wubin1989/.gvm/pkgsets/go1.23.4/global",
6-
"go.goroot": "/Users/wubin1989/.gvm/gos/go1.23.4",
7-
"go.formatTool": "goimports",
8-
"[go]": {
9-
"editor.formatOnSave": true,
10-
"editor.codeActionsOnSave": {
11-
"source.organizeImports": "explicit"
12-
}
13-
},
14-
"go.delveConfig": {
15-
"dlvLoadConfig": {
16-
"followPointers": true,
17-
"maxVariableRecurse": 1,
18-
"maxStringLen": 2048,
19-
"maxArrayValues": 64,
20-
"maxStructFields": -1
21-
},
22-
"apiVersion": 2,
23-
"showGlobalVariables": false
24-
}
25-
}
2+
"files.exclude": {
3+
"ecod-canal": true,
4+
"vanho": true
5+
},
6+
"go.useLanguageServer": true,
7+
"go.toolsManagement.autoUpdate": true,
8+
"go.gopath": "D:/gopath",
9+
"go.goroot": "C:/Users/wubin48435/.gvm/versions/go1.23.6.windows.amd64",
10+
"go.formatTool": "goimports",
11+
"[go]": {
12+
"editor.formatOnSave": true,
13+
"editor.codeActionsOnSave": {
14+
"source.organizeImports": "explicit"
15+
}
16+
},
17+
"go.delveConfig": {
18+
"dlvLoadConfig": {
19+
"followPointers": true,
20+
"maxVariableRecurse": 1,
21+
"maxStringLen": 2048,
22+
"maxArrayValues": 64,
23+
"maxStructFields": -1
24+
},
25+
"apiVersion": 2,
26+
"showGlobalVariables": false
27+
}
28+
}

caches/caches.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ func (c *Caches) AfterCommit(db *gorm.DB) {
224224
}
225225

226226
func (c *Caches) ease(db *gorm.DB, identifier string, callback func(*gorm.DB)) {
227-
if c.Conf.Easer == false {
228-
//if true {
227+
if !c.Conf.Easer {
229228
callback(db)
230229
return
231230
}
@@ -242,10 +241,18 @@ func (c *Caches) ease(db *gorm.DB, identifier string, callback func(*gorm.DB)) {
242241
}
243242

244243
if res.db.Statement.Dest == db.Statement.Dest {
245-
elementValue := reflect.ValueOf(res.db.Statement.Dest).Elem()
246-
elementType := elementValue.Type()
247-
v := reflect.New(elementType)
248-
db.Statement.Dest = v.Interface()
244+
245+
resultValue := reflect.ValueOf(res.db.Statement.Dest)
246+
247+
if resultValue.IsValid() && !resultValue.IsZero() && resultValue.Kind() == reflect.Ptr {
248+
elementValue := resultValue.Elem()
249+
elementType := elementValue.Type()
250+
v := reflect.New(elementType)
251+
db.Statement.Dest = v.Interface()
252+
} else {
253+
return
254+
}
255+
249256
}
250257

251258
q := Query{

0 commit comments

Comments
 (0)