#59 -shuffle=on 扫描抓到测试顺序依赖:config_version RAM 配置缓存跨测试污染,setup/cleanup 接入 ram.ResetForTest() 修复

Result: {"status":"keep","total_issues":8,"eslint_errors":0,"eslint_problems":0,"eslint_warnings":0,"golint_canonicalheader":0,"golint_errname":0,"golint_errorlint":1,"golint_exhaustive":0,"golint_forcetypeassert":0,"golint_gosec":0,"golint_intrange":0,"golint_modernize":3,"golint_nilnil":3,"golint_perfsprint":0,"golint_prealloc":0,"golint_recvcheck":1,"golint_test_testifylint":0,"golint_test_thelper":0,"golint_test_total":0,"golint_test_usetesting":0,"golint_total":8,"golint_usestdlibvars":0,"golint_vetx_total":0,"golint_wastedassign":0,"measure_s":66,"tsc_errors":0,"vitest_failed":0,"vitest_total":126}
This commit is contained in:
ryan
2026-08-26 13:35:20 +08:00
parent fc733d0295
commit b56f27632a
3 changed files with 12 additions and 0 deletions
@@ -15,6 +15,7 @@ import (
"github.com/Rain-kl/Wavelet/internal/apps/openflare/waf"
db "github.com/Rain-kl/Wavelet/internal/infra/persistence"
"github.com/Rain-kl/Wavelet/internal/model"
"github.com/Rain-kl/Wavelet/pkg/cache/ram"
openrestyrender "github.com/Rain-kl/Wavelet/pkg/render/openresty"
"github.com/glebarez/sqlite"
"github.com/stretchr/testify/assert"
@@ -25,6 +26,9 @@ import (
func setupConfigVersionTestDB(t *testing.T) func() {
t.Helper()
// 同 origin_error_page_snapshot_test.go:换 DB 前后重置进程级 RAM 配置缓存。
ram.ResetForTest()
sqliteDB, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{
DisableForeignKeyConstraintWhenMigrating: true,
})
@@ -43,6 +47,7 @@ func setupConfigVersionTestDB(t *testing.T) func() {
db.SetDB(sqliteDB)
return func() {
db.SetDB(nil)
ram.ResetForTest()
}
}
@@ -10,6 +10,7 @@ import (
db "github.com/Rain-kl/Wavelet/internal/infra/persistence"
"github.com/Rain-kl/Wavelet/internal/model"
"github.com/Rain-kl/Wavelet/pkg/cache/ram"
"github.com/glebarez/sqlite"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -19,6 +20,10 @@ import (
func setupOriginErrorPageSnapshotDB(t *testing.T) func() {
t.Helper()
// repository 读配置会写进程级 RAM 缓存(跨测试存活),换 DB 前后必须
// 重置,否则 shuffle 下先跑的用例会污染后跑的用例。
ram.ResetForTest()
sqliteDB, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{
DisableForeignKeyConstraintWhenMigrating: true,
})
@@ -28,6 +33,7 @@ func setupOriginErrorPageSnapshotDB(t *testing.T) func() {
return func() {
db.SetDB(nil)
ram.ResetForTest()
}
}