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.
131 lines
4.7 KiB
131 lines
4.7 KiB
package comm
|
|
|
|
import "testing"
|
|
|
|
func TestAppReleaseNeedForceUpdate(t *testing.T) {
|
|
on := &AppRelease{ForceUpdate: true, MinVersion: "2.0.0"}
|
|
if !on.NeedForceUpdate("1.9.9") {
|
|
t.Fatal("低于最低版本应强更")
|
|
}
|
|
if on.NeedForceUpdate("2.0.0") || on.NeedForceUpdate("2.1.0") {
|
|
t.Fatal("达到或高于最低版本不该强更")
|
|
}
|
|
if on.NeedForceUpdate("") {
|
|
t.Fatal("客户端未上报版本时不该强更,否则老客户端会被全挡在门外")
|
|
}
|
|
off := &AppRelease{ForceUpdate: false, MinVersion: "2.0.0"}
|
|
if off.NeedForceUpdate("1.0.0") {
|
|
t.Fatal("强更开关关闭时不该强更")
|
|
}
|
|
noMin := &AppRelease{ForceUpdate: true}
|
|
if noMin.NeedForceUpdate("1.0.0") {
|
|
t.Fatal("未配最低版本时不该强更")
|
|
}
|
|
var nilRel *AppRelease
|
|
if nilRel.NeedForceUpdate("1.0.0") {
|
|
t.Fatal("nil 配置不该强更")
|
|
}
|
|
}
|
|
|
|
func TestAppReleaseNeedUpdate(t *testing.T) {
|
|
r := &AppRelease{Version: "1.2.0"}
|
|
if !r.NeedUpdate("1.1.9") {
|
|
t.Fatal("低于线上版本应提示有更新")
|
|
}
|
|
if r.NeedUpdate("1.2.0") || r.NeedUpdate("1.3.0") {
|
|
t.Fatal("不低于线上版本时不该提示更新")
|
|
}
|
|
if r.NeedUpdate("") {
|
|
t.Fatal("客户端未上报版本时不该提示更新")
|
|
}
|
|
if (&AppRelease{}).NeedUpdate("1.0.0") {
|
|
t.Fatal("未配线上版本时恒为 false")
|
|
}
|
|
}
|
|
|
|
func TestAppReleaseIsReviewing(t *testing.T) {
|
|
r := &AppRelease{ReviewVersion: "3.1.0"}
|
|
if !r.IsReviewing("3.1.0") {
|
|
t.Fatal("送审版本应识别为审核中")
|
|
}
|
|
if r.IsReviewing("3.0.0") || r.IsReviewing("3.2.0") {
|
|
t.Fatal("非送审版本不该识别为审核中")
|
|
}
|
|
if (&AppRelease{}).IsReviewing("3.1.0") {
|
|
t.Fatal("未配送审版本时恒为 false")
|
|
}
|
|
}
|
|
|
|
// 游客登录的版本限定:这是应用商店过审期的开关,判错要么违规放行、要么审核员看不到入口被拒,
|
|
// 三段语义各钉一条。
|
|
func TestAppReleaseShowTourists(t *testing.T) {
|
|
// 总开关关掉:无论版本、无论有没有配生效版本,一律隐藏。
|
|
off := &AppRelease{Tourists: false, TouristsVersion: "1.0.2"}
|
|
if off.ShowTourists("1.0.2") {
|
|
t.Fatal("总开关关掉时不该显示游客登录")
|
|
}
|
|
|
|
// 开关开、但没点名任何版本:一律隐藏。白名单语义,不是「没限定就全放行」——
|
|
// 判宽的后果是不该露游客入口的版本露了出去,判严只是入口少显示。
|
|
none := &AppRelease{Tourists: true}
|
|
for _, v := range []string{"1.0.2", "9.9.9", ""} {
|
|
if none.ShowTourists(v) {
|
|
t.Fatalf("未填生效版本时 %q 不该可见", v)
|
|
}
|
|
}
|
|
|
|
// 开关开、点名 1.0.2:只有这一版可见,高于/低于/没上报一律隐藏。
|
|
only := &AppRelease{Tourists: true, TouristsVersion: "1.0.2"}
|
|
if !only.ShowTourists("1.0.2") {
|
|
t.Fatal("被点名的版本应可见")
|
|
}
|
|
// "1.0.2" == "1.0.2.0":段数不同按 0 补齐,别因为后台填了三段、客户端报四段就判不匹配。
|
|
if !only.ShowTourists("1.0.2.0") {
|
|
t.Fatal("补零等价的版本应可见")
|
|
}
|
|
for _, v := range []string{"1.0.1", "1.0.3", "1.0.20", "2.0.0", ""} {
|
|
if only.ShowTourists(v) {
|
|
t.Fatalf("点名 1.0.2 时 %q 不该可见", v)
|
|
}
|
|
}
|
|
|
|
var nilRel *AppRelease
|
|
if nilRel.ShowTourists("1.0.2") {
|
|
t.Fatal("未配置发版信息时不该显示游客登录")
|
|
}
|
|
}
|
|
|
|
// 下载地址必须允许按渠道覆盖:华为/小米/App Store 的商店链接各不相同,
|
|
// 客户端是直接把它当 URL 打开的,一套地址会把小米用户引到华为商店。
|
|
func TestAppReleaseDownloadAddress(t *testing.T) {
|
|
r := &AppRelease{Address: "https://default/app.apk"}
|
|
if got := r.DownloadAddress("https://xiaomi/store"); got != "https://xiaomi/store" {
|
|
t.Fatalf("渠道填了地址应以渠道为准,实际 %q", got)
|
|
}
|
|
if got := r.DownloadAddress(" "); got != "https://default/app.apk" {
|
|
t.Fatalf("渠道留空应回退应用默认地址,实际 %q", got)
|
|
}
|
|
var nilRel *AppRelease
|
|
if got := nilRel.DownloadAddress(""); got != "" {
|
|
t.Fatalf("两边都没有时应为空串,实际 %q", got)
|
|
}
|
|
if got := nilRel.DownloadAddress("https://only-channel"); got != "https://only-channel" {
|
|
t.Fatalf("发版配置缺失时仍应用渠道地址,实际 %q", got)
|
|
}
|
|
}
|
|
|
|
func TestPickAppRelease(t *testing.T) {
|
|
rows := []*AppRelease{
|
|
{AppName: "", Version: "1.0.0"},
|
|
{AppName: "ym", Version: "2.0.0"},
|
|
}
|
|
if got := PickAppRelease(rows, "ym"); got == nil || got.Version != "2.0.0" {
|
|
t.Fatalf("应用行应覆盖全局行,实际 %+v", got)
|
|
}
|
|
if got := PickAppRelease(rows, "other"); got == nil || got.Version != "1.0.0" {
|
|
t.Fatalf("没有应用行时应回退全局行,实际 %+v", got)
|
|
}
|
|
if got := PickAppRelease([]*AppRelease{{AppName: "ym"}}, "other"); got != nil {
|
|
t.Fatalf("既无应用行也无全局行时应返回 nil,实际 %+v", got)
|
|
}
|
|
}
|
|
|