test✅: restore the tenant's previous database after the opera log test

sdk.Runtime is process-wide, so setting the tenant back to nil on cleanup
could overwrite a mapping another test had installed. Save the previous
value and put it back, as common/middleware/db_test.go does.
This commit is contained in:
zhangwenjian
2026-10-01 22:09:55 +08:00
parent 8af88968b1
commit 3afe083499
+2 -1
View File
@@ -23,8 +23,9 @@ func TestSaveOperaLogTruncatesOnCharacterBoundary(t *testing.T) {
if err := db.AutoMigrate(&SysOperaLog{}); err != nil {
t.Fatalf("migrate: %v", err)
}
previous := sdk.Runtime.GetDbByTenant(tenant)
sdk.Runtime.SetDbByTenant(tenant, db)
t.Cleanup(func() { sdk.Runtime.SetDbByTenant(tenant, nil) })
t.Cleanup(func() { sdk.Runtime.SetDbByTenant(tenant, previous) })
// 150 characters, 3 bytes each: byte 100 falls inside the 34th character.
long := strings.Repeat("中", 150)