fix
This commit is contained in:
@@ -27,10 +27,8 @@ type Config struct {
|
||||
Wallet WalletConfig `mapstructure:"wallet"`
|
||||
WestDex WestDexConfig `mapstructure:"westdex"`
|
||||
AliPay AliPayConfig `mapstructure:"alipay"`
|
||||
Recharge RechargeConfig `mapstructure:"recharge"`
|
||||
Yushan YushanConfig `mapstructure:"yushan"`
|
||||
TianYanCha TianYanChaConfig `mapstructure:"tianyancha"`
|
||||
Domain DomainConfig `mapstructure:"domain"`
|
||||
}
|
||||
|
||||
// ServerConfig HTTP服务器配置
|
||||
@@ -275,7 +273,16 @@ type SignConfig struct {
|
||||
|
||||
// WalletConfig 钱包配置
|
||||
type WalletConfig struct {
|
||||
DefaultCreditLimit float64 `mapstructure:"default_credit_limit"`
|
||||
DefaultCreditLimit float64 `mapstructure:"default_credit_limit"`
|
||||
MinAmount string `mapstructure:"min_amount"` // 最低充值金额
|
||||
MaxAmount string `mapstructure:"max_amount"` // 最高充值金额
|
||||
AliPayRechargeBonus []AliPayRechargeBonusRule `mapstructure:"alipay_recharge_bonus"`
|
||||
}
|
||||
|
||||
// AliPayRechargeBonusRule 支付宝充值赠送规则
|
||||
type AliPayRechargeBonusRule struct {
|
||||
RechargeAmount float64 `mapstructure:"recharge_amount"` // 充值金额
|
||||
BonusAmount float64 `mapstructure:"bonus_amount"` // 赠送金额
|
||||
}
|
||||
|
||||
// WestDexConfig WestDex配置
|
||||
@@ -296,12 +303,6 @@ type AliPayConfig struct {
|
||||
ReturnURL string `mapstructure:"return_url"`
|
||||
}
|
||||
|
||||
// RechargeConfig 充值配置
|
||||
type RechargeConfig struct {
|
||||
MinAmount string `mapstructure:"min_amount"` // 最低充值金额
|
||||
MaxAmount string `mapstructure:"max_amount"` // 最高充值金额
|
||||
}
|
||||
|
||||
// YushanConfig 羽山配置
|
||||
type YushanConfig struct {
|
||||
URL string `mapstructure:"url"`
|
||||
|
||||
53
internal/config/config_test.go
Normal file
53
internal/config/config_test.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestWalletConfig_AlipayRechargeBonus(t *testing.T) {
|
||||
// 切换到项目根目录,这样配置加载器就能找到配置文件
|
||||
originalWd, err := os.Getwd()
|
||||
assert.NoError(t, err)
|
||||
|
||||
// 切换到项目根目录(从 internal/config 目录向上两级)
|
||||
err = os.Chdir("../../")
|
||||
assert.NoError(t, err)
|
||||
defer os.Chdir(originalWd) // 测试结束后恢复原目录
|
||||
|
||||
// 加载配置
|
||||
cfg, err := LoadConfig()
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, cfg)
|
||||
|
||||
// 验证钱包配置
|
||||
assert.NotNil(t, cfg.Wallet)
|
||||
assert.Greater(t, len(cfg.Wallet.AliPayRechargeBonus), 0, "支付宝充值赠送规则不能为空")
|
||||
|
||||
// 验证具体的赠送规则
|
||||
expectedRules := []struct {
|
||||
rechargeAmount float64
|
||||
bonusAmount float64
|
||||
}{
|
||||
{1000.00, 50.00}, // 充1000送50
|
||||
{5000.00, 300.00}, // 充5000送300
|
||||
{10000.00, 800.00}, // 充10000送800
|
||||
}
|
||||
|
||||
for i, expected := range expectedRules {
|
||||
if i < len(cfg.Wallet.AliPayRechargeBonus) {
|
||||
rule := cfg.Wallet.AliPayRechargeBonus[i]
|
||||
assert.Equal(t, expected.rechargeAmount, rule.RechargeAmount,
|
||||
"充值金额不匹配,期望: %f, 实际: %f", expected.rechargeAmount, rule.RechargeAmount)
|
||||
assert.Equal(t, expected.bonusAmount, rule.BonusAmount,
|
||||
"赠送金额不匹配,期望: %f, 实际: %f", expected.bonusAmount, rule.BonusAmount)
|
||||
}
|
||||
}
|
||||
|
||||
t.Logf("钱包配置加载成功,包含 %d 条支付宝充值赠送规则", len(cfg.Wallet.AliPayRechargeBonus))
|
||||
for i, rule := range cfg.Wallet.AliPayRechargeBonus {
|
||||
t.Logf("规则 %d: 充值 %.2f 元,赠送 %.2f 元", i+1, rule.RechargeAmount, rule.BonusAmount)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user