mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 22:06:38 +08:00
299ac30ee4
- Purify core micro-kernel by removing context hardcoded helpers and reverse dependencies - Eliminate init() side effects in infra plugins with reversible lifecycle disposal - Completely isolate plugins by removing cross-plugin imports and using core/contracts - Introduce TaskService and RiskControlService contracts for unified cross-plugin APIs - Regenerate Swagger documentation and update developer guide matrix - Achieve 0 violations in check_cordis_architecture.sh and 100% test pass
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package diskcache
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"Wavelet/pkg/testhelper"
|
|
)
|
|
|
|
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)
|
|
}
|
|
}
|