From 3afe083499b1404350ae15d8e075473cf5e5c1d7 Mon Sep 17 00:00:00 2001 From: zhangwenjian Date: Thu, 1 Oct 2026 22:09:55 +0800 Subject: [PATCH] =?UTF-8?q?test=E2=9C=85:=20restore=20the=20tenant's=20pre?= =?UTF-8?q?vious=20database=20after=20the=20opera=20log=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- app/admin/models/sys_opera_log_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/admin/models/sys_opera_log_test.go b/app/admin/models/sys_opera_log_test.go index 291cdbf8..4da298fe 100644 --- a/app/admin/models/sys_opera_log_test.go +++ b/app/admin/models/sys_opera_log_test.go @@ -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)