onesvm-browser-server/server/internal/config/config_test.go
chii eb972dfa93 feat: 落地 browser-server 控制面并打通 mgr1 海外订阅
单二进制三角色 + Dock 适配器 + Swarm stack 达到可部署态;mgr1 实测订阅经 central-proxy bootstrap,探活 alive=41/52。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-02 15:05:12 +08:00

63 lines
1.7 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// config_test.go:fail-closed 纪律(A6.1 关键路径)。
package config
import (
"strings"
"testing"
"time"
)
// TestMustEnvFailClosed 未设置环境变量必须 panic,禁止默认值兜底。
func TestMustEnvFailClosed(t *testing.T) {
t.Setenv("BS_TEST_SECRET_MISSING", "") // 显式置空模拟未设置
defer func() {
r := recover()
if r == nil {
t.Fatal("MustEnv 缺失应 panic(fail-closed)")
}
msg, ok := r.(string)
if !ok || !strings.Contains(msg, "BS_TEST_SECRET_MISSING") {
t.Fatalf("panic 信息应含变量名: %v", r)
}
}()
MustEnv("BS_TEST_SECRET_MISSING")
}
// TestMustEnvPresent 已设置时正常返回。
func TestMustEnvPresent(t *testing.T) {
t.Setenv("BS_TEST_SECRET_PRESENT", "s3cret")
if v := MustEnv("BS_TEST_SECRET_PRESENT"); v != "s3cret" {
t.Fatalf("取值不符: %s", v)
}
}
// TestEnvDefault 非密钥缺省路径。
func TestEnvDefault(t *testing.T) {
if v := EnvDefault("BS_TEST_PORT_UNSET", ":8640"); v != ":8640" {
t.Fatalf("缺省值不符: %s", v)
}
t.Setenv("BS_TEST_PORT_SET", ":9999")
if v := EnvDefault("BS_TEST_PORT_SET", ":8640"); v != ":9999" {
t.Fatalf("覆盖值不符: %s", v)
}
}
// TestTimezone 时区常量与 Now 输出偏移。
func TestTimezone(t *testing.T) {
if Timezone != "Asia/Shanghai" {
t.Fatalf("时区常量不符: %s", Timezone)
}
now := Now()
if _, offset := now.Zone(); offset != 8*3600 {
t.Fatalf("Now 应为 +08:00: offset=%d", offset)
}
}
// TestTZSerialization 时间格式含 +08:00。
func TestTimezoneFormat(t *testing.T) {
if !strings.Contains(Now().Format("2006-01-02T15:04:05-07:00"), "+08:00") {
t.Fatal("Now 格式化应带 +08:00")
}
}
var _ = time.Now // 锚点:time 依赖保留