Files
full/pkgs/all/internal/config/config_test.go

41 lines
1.3 KiB
Go
Raw Normal View History

2026-08-10 11:16:02 +08:00
package config
import (
"os"
"path/filepath"
"testing"
"go.yaml.in/yaml/v3"
)
func TestAllDevConfig(t *testing.T) {
2026-09-22 21:15:34 +08:00
// dev 配置中的密钥已改为环境变量占位,测试按进程实际展开后再校验结构。
t.Setenv("BSM_JwtSecretKey", "0123456789abcdef0123456789abcdef")
t.Setenv("BSM_SECRET_KEY", "0123456789abcdef0123456789abcdef")
data, err := os.ReadFile(filepath.Join("..", "..", "etc", "default_dev.yaml"))
2026-08-10 11:16:02 +08:00
if err != nil {
t.Fatal(err)
}
var cfg SrvConfig
2026-09-22 21:15:34 +08:00
if err := yaml.Unmarshal([]byte(os.ExpandEnv(string(data))), &cfg); err != nil {
2026-08-10 11:16:02 +08:00
t.Fatal(err)
}
if len(cfg.Services) == 0 {
t.Fatal("services must not be empty")
}
if cfg.Server.GRPC.Port == "" || cfg.Server.HTTP.Port == "" || cfg.Server.GRPC.Port == cfg.Server.HTTP.Port {
t.Fatal("separate gRPC and HTTP ports are required")
}
if cfg.Authorization.Key == "" || cfg.Authorization.Expire <= 0 {
t.Fatal("authorization key and expiration are required")
}
keyLength := len(cfg.Authorization.Key)
if keyLength != 16 && keyLength != 24 && keyLength != 32 {
t.Fatal("authorization key must be compatible with the JWT issuer")
}
2026-08-10 11:16:02 +08:00
if cfg.Fts == nil || cfg.Mgt == nil || cfg.Passport == nil || cfg.Sender == nil || cfg.Wallet == nil {
t.Fatal("service-specific configuration is incomplete")
}
}