108 lines
3.7 KiB
Go
108 lines
3.7 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestNormalizeLuckyGiftConfigsKeepsDedicatedAccountWhenSharedPresent(t *testing.T) {
|
|
configs := normalizeLuckyGiftConfigs([]LuckyGiftProviderConfig{
|
|
{
|
|
StandardID: 18816,
|
|
URL: "https://provider.example.com",
|
|
AppID: "lucky-app-id",
|
|
AppChannel: "lucky-app-channel",
|
|
AppKey: "legacy-lucky-key",
|
|
},
|
|
}, "shared-baishun-app-id", "shared-baishun-app-channel", "shared-baishun-key")
|
|
if len(configs) != 1 {
|
|
t.Fatalf("expected 1 config, got %d", len(configs))
|
|
}
|
|
if got := configs[0].AppID; got != "lucky-app-id" {
|
|
t.Fatalf("expected dedicated lucky gift app id, got %q", got)
|
|
}
|
|
if got := configs[0].AppChannel; got != "lucky-app-channel" {
|
|
t.Fatalf("expected dedicated lucky gift app channel, got %q", got)
|
|
}
|
|
if got := configs[0].AppKey; got != "legacy-lucky-key" {
|
|
t.Fatalf("expected dedicated lucky gift key, got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeLuckyGiftConfigsFallsBackToSharedAccountWhenDedicatedBlank(t *testing.T) {
|
|
configs := normalizeLuckyGiftConfigs([]LuckyGiftProviderConfig{
|
|
{
|
|
StandardID: 18816,
|
|
URL: "https://provider.example.com",
|
|
},
|
|
}, "shared-baishun-app-id", "shared-baishun-app-channel", "shared-baishun-key")
|
|
if len(configs) != 1 {
|
|
t.Fatalf("expected 1 config, got %d", len(configs))
|
|
}
|
|
if got := configs[0].AppID; got != "shared-baishun-app-id" {
|
|
t.Fatalf("expected shared baishun app id fallback, got %q", got)
|
|
}
|
|
if got := configs[0].AppChannel; got != "shared-baishun-app-channel" {
|
|
t.Fatalf("expected shared baishun app channel fallback, got %q", got)
|
|
}
|
|
if got := configs[0].AppKey; got != "shared-baishun-key" {
|
|
t.Fatalf("expected shared baishun key fallback, got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestGetEnvBoolAliasSupportsLegacyLuckyGiftKey(t *testing.T) {
|
|
t.Setenv("LUCKY_GIFT_GO_ENABLED", "true")
|
|
if got := getEnvBoolAny([]string{"LUCKY_GIFT_ENABLED", "LUCKY_GIFT_GO_ENABLED"}, false); !got {
|
|
t.Fatalf("expected legacy lucky gift bool alias to be true")
|
|
}
|
|
}
|
|
|
|
func TestLoadLingxianConfigSupportsLikeiHkysSignKey(t *testing.T) {
|
|
t.Setenv("LIKEI_GAME_HKYS_SIGN_KEY", "likei-hkys-key")
|
|
|
|
cfg := Load()
|
|
if got := cfg.Lingxian.AppKey; got != "likei-hkys-key" {
|
|
t.Fatalf("expected legacy likei hkys sign key, got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestLoadLuckyGiftConfigsSupportsLegacyDefaultEnv(t *testing.T) {
|
|
oldJSON, hadJSON := os.LookupEnv("LUCKY_GIFT_CONFIGS_JSON")
|
|
oldList, hadList := os.LookupEnv("LUCKY_GIFT_CONFIGS")
|
|
t.Cleanup(func() {
|
|
if hadJSON {
|
|
_ = os.Setenv("LUCKY_GIFT_CONFIGS_JSON", oldJSON)
|
|
} else {
|
|
_ = os.Unsetenv("LUCKY_GIFT_CONFIGS_JSON")
|
|
}
|
|
if hadList {
|
|
_ = os.Setenv("LUCKY_GIFT_CONFIGS", oldList)
|
|
} else {
|
|
_ = os.Unsetenv("LUCKY_GIFT_CONFIGS")
|
|
}
|
|
})
|
|
_ = os.Unsetenv("LUCKY_GIFT_CONFIGS_JSON")
|
|
_ = os.Unsetenv("LUCKY_GIFT_CONFIGS")
|
|
t.Setenv("LUCKY_GIFT_API_DEFAULT_URL", "https://provider.example.com/lucky_gift/start_game")
|
|
t.Setenv("LUCKY_GIFT_API_DEFAULT_APP_ID", "legacy-app-id")
|
|
t.Setenv("LUCKY_GIFT_API_DEFAULT_APP_CHANNEL", "legacy-app-channel")
|
|
t.Setenv("LUCKY_GIFT_API_DEFAULT_APP_KEY", "legacy-app-key")
|
|
|
|
configs := loadLuckyGiftConfigs()
|
|
if len(configs) != 1 {
|
|
t.Fatalf("expected 1 config, got %d", len(configs))
|
|
}
|
|
if got := configs[0].URL; got != "https://provider.example.com/lucky_gift/start_game" {
|
|
t.Fatalf("expected legacy lucky gift default url, got %q", got)
|
|
}
|
|
if got := configs[0].AppID; got != "legacy-app-id" {
|
|
t.Fatalf("expected legacy lucky gift default app id, got %q", got)
|
|
}
|
|
if got := configs[0].AppChannel; got != "legacy-app-channel" {
|
|
t.Fatalf("expected legacy lucky gift default app channel, got %q", got)
|
|
}
|
|
if got := configs[0].AppKey; got != "legacy-app-key" {
|
|
t.Fatalf("expected legacy lucky gift default app key, got %q", got)
|
|
}
|
|
}
|