102 lines
3.4 KiB
Go
102 lines
3.4 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestNormalizeLuckyGiftConfigsUsesSharedBaishunAppKey(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 != "shared-baishun-app-id" {
|
|
t.Fatalf("expected baishun app id override, got %q", got)
|
|
}
|
|
if got := configs[0].AppChannel; got != "shared-baishun-app-channel" {
|
|
t.Fatalf("expected baishun app channel override, got %q", got)
|
|
}
|
|
if got := configs[0].AppKey; got != "shared-baishun-key" {
|
|
t.Fatalf("expected baishun key override, got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeLuckyGiftConfigsKeepsDedicatedKeyWhenSharedBlank(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",
|
|
},
|
|
}, "", "", "")
|
|
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 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 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)
|
|
}
|
|
}
|