- Deleted the Token model and its repository, transitioning to a Redis-based token management system. - Updated the service layer to utilize Redis for token storage, enhancing performance and scalability. - Refactored the container to remove TokenRepository and integrate the new token service. - Cleaned up the Dockerfile and other files by removing unnecessary whitespace and comments. - Enhanced error handling and logging for Redis initialization and usage.
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package config
|
||
|
||
import (
|
||
"os"
|
||
"testing"
|
||
|
||
"github.com/spf13/viper"
|
||
)
|
||
|
||
// 重置 viper,避免测试间干扰
|
||
func resetViper() {
|
||
viper.Reset()
|
||
}
|
||
|
||
func TestLoad_DefaultsAndBucketsOverride(t *testing.T) {
|
||
resetViper()
|
||
// 设置部分环境变量覆盖
|
||
_ = os.Setenv("RUSTFS_BUCKET_TEXTURES", "tex-bkt")
|
||
_ = os.Setenv("RUSTFS_BUCKET_AVATARS", "ava-bkt")
|
||
_ = os.Setenv("DATABASE_MAX_IDLE_CONNS", "20")
|
||
_ = os.Setenv("DATABASE_MAX_OPEN_CONNS", "50")
|
||
_ = os.Setenv("DATABASE_CONN_MAX_LIFETIME", "2h")
|
||
_ = os.Setenv("DATABASE_CONN_MAX_IDLE_TIME", "30m")
|
||
|
||
cfg, err := Load()
|
||
if err != nil {
|
||
t.Fatalf("Load err: %v", err)
|
||
}
|
||
|
||
// 默认值检查
|
||
if cfg.Server.Port == "" || cfg.Database.Driver == "" || cfg.Redis.Host == "" {
|
||
t.Fatalf("expected defaults filled: %+v", cfg)
|
||
}
|
||
|
||
// 覆盖检查
|
||
if cfg.RustFS.Buckets["textures"] != "tex-bkt" || cfg.RustFS.Buckets["avatars"] != "ava-bkt" {
|
||
t.Fatalf("buckets override failed: %+v", cfg.RustFS.Buckets)
|
||
}
|
||
if cfg.Database.MaxIdleConns != 20 || cfg.Database.MaxOpenConns != 50 {
|
||
t.Fatalf("db pool override failed: %+v", cfg.Database)
|
||
}
|
||
if cfg.Database.ConnMaxLifetime.String() != "2h0m0s" || cfg.Database.ConnMaxIdleTime.String() != "30m0s" {
|
||
t.Fatalf("db duration override failed: %v %v", cfg.Database.ConnMaxLifetime, cfg.Database.ConnMaxIdleTime)
|
||
}
|
||
}
|
||
|
||
|