mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 14:06:36 +08:00
528240026d
- make format 现在与 code-check 使用同一格式化器(golangci-lint fmt),消除 goimports -local 与 gofumpt 的格式拉锯 - .golangci.yml 关闭默认 50/3 截断,完整上报所有问题(只增强不弱化) - 全库 gofumpt 规范化(203 files, 纯格式无行为变更)
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package diskcache
|
|
|
|
import (
|
|
"Wavelet/pkg/testhelper"
|
|
"context"
|
|
"testing"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type mockDBService struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func (m *mockDBService) GORM() *gorm.DB {
|
|
return m.db
|
|
}
|
|
|
|
func (m *mockDBService) DB(ctx context.Context) *gorm.DB {
|
|
return m.db.WithContext(ctx)
|
|
}
|
|
|
|
func (m *mockDBService) Named(_ string) *gorm.DB {
|
|
return m.db
|
|
}
|
|
|
|
func TestDiskCacheReloadConfig(t *testing.T) {
|
|
dbConn, _, cleanup := testhelper.SetupTestEnvironment(t)
|
|
SetDBService(&mockDBService{db: dbConn})
|
|
defer func() {
|
|
SetDBService(nil)
|
|
cleanup()
|
|
}()
|
|
|
|
testDir := t.TempDir()
|
|
|
|
c := New(testDir)
|
|
defer func() { _ = c.Clear() }()
|
|
|
|
// Update DB config values
|
|
dbConn.Table("w_system_configs").Where("key = ?", "disk_cache_max_size_mb").Update("value", "250")
|
|
dbConn.Table("w_system_configs").Where("key = ?", "disk_cache_ttl_minutes").Update("value", "120")
|
|
dbConn.Table("w_system_configs").Where("key = ?", "disk_cache_lru_enabled").Update("value", "false")
|
|
|
|
// Reload config
|
|
c.ReloadConfig(context.Background())
|
|
|
|
status := c.Status()
|
|
if status.MaxSizeMB != 250 {
|
|
t.Errorf("expected MaxSizeMB to be 250, got %d", status.MaxSizeMB)
|
|
}
|
|
if status.TTLMinutes != 120 {
|
|
t.Errorf("expected TTLMinutes to be 120, got %d", status.TTLMinutes)
|
|
}
|
|
if status.LRUEnabled != false {
|
|
t.Errorf("expected LRUEnabled to be false, got %v", status.LRUEnabled)
|
|
}
|
|
}
|