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.
84 lines
2.7 KiB
84 lines
2.7 KiB
package user
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"yunyan/comm"
|
|
)
|
|
|
|
func mtSvc(app, id, provider string, enable bool) *comm.ThirdSvcConfig {
|
|
return &comm.ThirdSvcConfig{
|
|
AppName: app,
|
|
Id: id,
|
|
Provider: provider,
|
|
Categories: "3", // comm.SvcCatMT
|
|
Enable: enable,
|
|
}
|
|
}
|
|
|
|
// 机器翻译只接微软。阿里即使启用也不再被挑中。
|
|
func TestPickMTSvcSkipsUnimplementedProviders(t *testing.T) {
|
|
svcs := []*comm.ThirdSvcConfig{
|
|
mtSvc("EAIMAR", "mt_volcano", "volcano", true),
|
|
mtSvc("EAIMAR", "mt_alibaba", "alibaba", true),
|
|
mtSvc("EAIMAR", "mt_azure", "azure", true),
|
|
}
|
|
picked, skipped := pickMTSvc(svcs, "EAIMAR")
|
|
if picked == nil || picked.Id != "mt_azure" {
|
|
t.Fatalf("应挑中 mt_azure,实际 %v", pickedIdOf(picked))
|
|
}
|
|
joined := strings.Join(skipped, ",")
|
|
if !strings.Contains(joined, "mt_alibaba") || !strings.Contains(joined, "mt_volcano") {
|
|
t.Fatalf("阿里和未接入的服务应记进 skipped,实际 %v", skipped)
|
|
}
|
|
}
|
|
|
|
// 全都没接入时返回 nil(调用方回 TranslateNotConfigured),
|
|
// 并且把跳过的列出来——否则「配了却报未配置」无从查起。
|
|
func TestPickMTSvcAllUnimplemented(t *testing.T) {
|
|
svcs := []*comm.ThirdSvcConfig{
|
|
mtSvc("EAIMAR", "mt_volcano", "volcano", true),
|
|
mtSvc("EAIMAR", "mt_alibaba", "alibaba", true),
|
|
}
|
|
picked, skipped := pickMTSvc(svcs, "EAIMAR")
|
|
if picked != nil {
|
|
t.Fatalf("没有接得上的服务时应返回 nil,实际 %v", picked.Id)
|
|
}
|
|
if len(skipped) != 2 {
|
|
t.Fatalf("skipped 应含两家,实际 %v", skipped)
|
|
}
|
|
}
|
|
|
|
// 停用的、类别不含 MT 的,一律不参与。
|
|
func TestPickMTSvcIgnoresDisabledAndOtherCategories(t *testing.T) {
|
|
other := mtSvc("EAIMAR", "stt_azure", "alibaba", true)
|
|
other.Categories = "1" // STT
|
|
svcs := []*comm.ThirdSvcConfig{
|
|
mtSvc("EAIMAR", "mt_alibaba", "alibaba", false), // 停用
|
|
other,
|
|
}
|
|
if picked, _ := pickMTSvc(svcs, "EAIMAR"); picked != nil {
|
|
t.Fatalf("停用/非 MT 类别不应被选中,实际 %v", picked.Id)
|
|
}
|
|
}
|
|
|
|
// 本应用的行优先于全局行(作用域归一后全局行已不再产生,这条守存量数据)。
|
|
func TestPickMTSvcPrefersAppScope(t *testing.T) {
|
|
svcs := []*comm.ThirdSvcConfig{
|
|
mtSvc("", "mt_azure", "azure", true),
|
|
mtSvc("EAIMAR", "mt_azure", "azure", true),
|
|
}
|
|
picked, _ := pickMTSvc(svcs, "EAIMAR")
|
|
if picked == nil || picked.AppName != "EAIMAR" {
|
|
t.Fatalf("应优先取本应用的行,实际 %v", picked)
|
|
}
|
|
}
|
|
|
|
// provider 是人手填的,大小写/空格不该影响匹配。
|
|
func TestPickMTSvcNormalizesProvider(t *testing.T) {
|
|
svcs := []*comm.ThirdSvcConfig{mtSvc("EAIMAR", "mt_azure", " Azure ", true)}
|
|
if picked, _ := pickMTSvc(svcs, "EAIMAR"); picked == nil {
|
|
t.Fatal("provider 大小写/空白不应影响匹配")
|
|
}
|
|
}
|
|
|