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.
45 lines
1.8 KiB
45 lines
1.8 KiB
package echomeet
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"yunyan/comm"
|
|
)
|
|
|
|
// langsOf 是能力清单下发的核心口径,容易被后续改动带偏,这里把三条约定钉死:
|
|
// 按编排顺序合并、大小写不敏感去重且保留后台原写法、不限语言的服务只置 anyLang 不进列表。
|
|
func TestLangsOf(t *testing.T) {
|
|
c := &providersComp{snap: &orchSnapshot{Services: map[string]*resolvedSvc{
|
|
"asr_a": {SvcId: "asr_a", Languages: []string{"zh-CN", "en-US"}},
|
|
"asr_b": {SvcId: "asr_b", Languages: []string{"EN-us", "ja-JP"}}, // 与 asr_a 的 en-US 重复(大小写不同)
|
|
"asr_c": {SvcId: "asr_c"}, // 未配 languages = 不限
|
|
"asr_no": {SvcId: "asr_no", Languages: []string{"ko-KR"}}, // 实例没构建成功,不该出现
|
|
}}}
|
|
list := []*comm.EchoOrchestration{
|
|
{SvcId: "asr_a"}, {SvcId: "asr_b"}, {SvcId: "asr_no"}, {SvcId: "missing"},
|
|
}
|
|
available := func(id string) bool { return id != "asr_no" }
|
|
|
|
langs, anyLang := c.langsOf(list, available)
|
|
want := []string{"zh-CN", "en-US", "ja-JP"}
|
|
if len(langs) != len(want) {
|
|
t.Fatalf("语言数量 = %v,期望 %v", langs, want)
|
|
}
|
|
for i, w := range want {
|
|
if langs[i] != w {
|
|
t.Fatalf("langs[%d] = %s,期望 %s(顺序应随编排优先级,写法保留后台原值)", i, langs[i], w)
|
|
}
|
|
}
|
|
if anyLang {
|
|
t.Fatalf("列表里没有不限语言的服务,anyLang 应为 false")
|
|
}
|
|
|
|
// 加入未配 languages 的服务:anyLang 置位,但它本身不往列表里塞东西。
|
|
langs2, anyLang2 := c.langsOf(append(list, &comm.EchoOrchestration{SvcId: "asr_c"}), available)
|
|
if !anyLang2 {
|
|
t.Fatalf("存在未配 languages 的服务时 anyLang 应为 true")
|
|
}
|
|
if len(langs2) != len(want) {
|
|
t.Fatalf("不限语言的服务不应改变语言列表,得到 %v", langs2)
|
|
}
|
|
}
|
|
|