83 lines
3.3 KiB
Go
83 lines
3.3 KiB
Go
|
|
package config
|
|||
|
|
|
|||
|
|
import (
|
|||
|
|
"path/filepath"
|
|||
|
|
"testing"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
// TestXiaomiDefaultValuesFromViper 验证:config.yaml 中小米字段留空时,
|
|||
|
|
// viper.SetDefault 设置的默认值(153608/153609 + M10289/P10761)能正确填充到 Config 结构体。
|
|||
|
|
// 这证明:不配置环境变量/yaml 值时,代码内置默认值生效。
|
|||
|
|
func TestXiaomiDefaultValuesFromViper(t *testing.T) {
|
|||
|
|
// 加载仓库内的 config.yaml(小米字段已留空,依赖代码默认值)
|
|||
|
|
yamlPath := filepath.Join("..", "..", "configs", "config.yaml")
|
|||
|
|
cfg, err := Load(yamlPath)
|
|||
|
|
if err != nil {
|
|||
|
|
t.Fatalf("Load config failed: %v", err)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
x := cfg.JPush.Channel.Vendor.Xiaomi
|
|||
|
|
if x.System != "153609" {
|
|||
|
|
t.Errorf("xiaomi.system default = %q, want 153609", x.System)
|
|||
|
|
}
|
|||
|
|
if x.Chat != "153608" {
|
|||
|
|
t.Errorf("xiaomi.chat default = %q, want 153608", x.Chat)
|
|||
|
|
}
|
|||
|
|
if x.MiSystemTemplateID != "P10761" {
|
|||
|
|
t.Errorf("xiaomi.mi_system_template_id default = %q, want P10761", x.MiSystemTemplateID)
|
|||
|
|
}
|
|||
|
|
if x.MiChatTemplateID != "M10289" {
|
|||
|
|
t.Errorf("xiaomi.mi_chat_template_id default = %q, want M10289", x.MiChatTemplateID)
|
|||
|
|
}
|
|||
|
|
t.Logf("小米默认值生效: system=%s chat=%s mi_sys=%s mi_chat=%s",
|
|||
|
|
x.System, x.Chat, x.MiSystemTemplateID, x.MiChatTemplateID)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// TestVendorDefaultValuesFromViper 验证:OPPO/vivo/荣耀的分类字段在 yaml 留空时,
|
|||
|
|
// viper.SetDefault 设置的默认值能正确填充到 Config 结构体。
|
|||
|
|
// channel_id 类字段需厂商后台注册,不在默认值范围(留空)。
|
|||
|
|
func TestVendorDefaultValuesFromViper(t *testing.T) {
|
|||
|
|
yamlPath := filepath.Join("..", "..", "configs", "config.yaml")
|
|||
|
|
cfg, err := Load(yamlPath)
|
|||
|
|
if err != nil {
|
|||
|
|
t.Fatalf("Load config failed: %v", err)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// OPPO: chat=IM/16, system=ACCOUNT/2
|
|||
|
|
oppo := cfg.JPush.Channel.Vendor.OPPO
|
|||
|
|
if oppo.OppoChatCategory != "IM" {
|
|||
|
|
t.Errorf("oppo.oppo_chat_category default = %q, want IM", oppo.OppoChatCategory)
|
|||
|
|
}
|
|||
|
|
if oppo.OppoSystemCategory != "ACCOUNT" {
|
|||
|
|
t.Errorf("oppo.oppo_system_category default = %q, want ACCOUNT", oppo.OppoSystemCategory)
|
|||
|
|
}
|
|||
|
|
if oppo.OppoChatNotifyLevel != 16 {
|
|||
|
|
t.Errorf("oppo.oppo_chat_notify_level default = %d, want 16", oppo.OppoChatNotifyLevel)
|
|||
|
|
}
|
|||
|
|
if oppo.OppoSystemNotifyLevel != 2 {
|
|||
|
|
t.Errorf("oppo.oppo_system_notify_level default = %d, want 2", oppo.OppoSystemNotifyLevel)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// vivo: chat=IM, system=ACCOUNT
|
|||
|
|
vivo := cfg.JPush.Channel.Vendor.VIVO
|
|||
|
|
if vivo.VivoChatCategory != "IM" {
|
|||
|
|
t.Errorf("vivo.vivo_chat_category default = %q, want IM", vivo.VivoChatCategory)
|
|||
|
|
}
|
|||
|
|
if vivo.VivoSystemCategory != "ACCOUNT" {
|
|||
|
|
t.Errorf("vivo.vivo_system_category default = %q, want ACCOUNT", vivo.VivoSystemCategory)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 荣耀: chat=NORMAL, system=LOW
|
|||
|
|
honor := cfg.JPush.Channel.Vendor.Honor
|
|||
|
|
if honor.HonorChatImportance != "NORMAL" {
|
|||
|
|
t.Errorf("honor.honor_chat_importance default = %q, want NORMAL", honor.HonorChatImportance)
|
|||
|
|
}
|
|||
|
|
if honor.HonorSystemImportance != "LOW" {
|
|||
|
|
t.Errorf("honor.honor_system_importance default = %q, want LOW", honor.HonorSystemImportance)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
t.Logf("OPPO: chat=%s/%d system=%s/%d", oppo.OppoChatCategory, oppo.OppoChatNotifyLevel, oppo.OppoSystemCategory, oppo.OppoSystemNotifyLevel)
|
|||
|
|
t.Logf("vivo: chat=%s system=%s", vivo.VivoChatCategory, vivo.VivoSystemCategory)
|
|||
|
|
t.Logf("荣耀: chat=%s system=%s", honor.HonorChatImportance, honor.HonorSystemImportance)
|
|||
|
|
}
|