You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.6 KiB
50 lines
1.6 KiB
package comm
|
|
|
|
import "testing"
|
|
|
|
func TestCompareVersion(t *testing.T) {
|
|
cases := []struct {
|
|
a, b string
|
|
want int
|
|
}{
|
|
{"1.0.0", "1.0.0", 0},
|
|
{"1.2", "1.2.0", 0}, // 段数不同,短的补 0
|
|
{"1.10.0", "1.9.0", 1}, // 字符串比较会判反,必须按整数
|
|
{"1.9.0", "1.10.0", -1},
|
|
{"2.0.0", "1.99.99", 1},
|
|
{"1.0.1", "1.0.0", 1},
|
|
{"1.0.0-beta", "1.0.0", 0}, // 非数字后缀取前导数字
|
|
{"1.2.3rc1", "1.2.3", 0},
|
|
{"", "1.0.0", -1},
|
|
{"1.0.0", "", 1},
|
|
}
|
|
for _, c := range cases {
|
|
if got := CompareVersion(c.a, c.b); got != c.want {
|
|
t.Fatalf("CompareVersion(%q,%q)=%d, 期望 %d", c.a, c.b, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPickChannelApp(t *testing.T) {
|
|
rows := []*ChannelApp{
|
|
{AppName: "", Channel: ChannelGlobalApple, Address: "global-apple"},
|
|
{AppName: "voitrans", Channel: ChannelGlobalApple, Address: "app-apple"},
|
|
{AppName: "", Channel: ChannelGlobalGoogle, Address: "global-google"},
|
|
}
|
|
if got := PickChannelApp(rows, ChannelGlobalApple); got == nil || got.Address != "app-apple" {
|
|
t.Fatalf("应用行应覆盖全局行,实际 %+v", got)
|
|
}
|
|
if got := PickChannelApp(rows, ChannelGlobalGoogle); got == nil || got.Address != "global-google" {
|
|
t.Fatalf("只有全局行时应回退全局,实际 %+v", got)
|
|
}
|
|
if got := PickChannelApp(rows, ChannelChinaHuawei); got != nil {
|
|
t.Fatalf("该渠道无配置时应返回 nil,实际 %+v", got)
|
|
}
|
|
}
|
|
|
|
func TestSplitPayChannels(t *testing.T) {
|
|
got := SplitPayChannels(" wxpay , ,apple ")
|
|
if len(got) != 2 || got[0] != PayWechat || got[1] != PayApple {
|
|
t.Fatalf("SplitPayChannels 结果异常: %#v", got)
|
|
}
|
|
}
|
|
|