mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-12-30 23:16:37 +08:00
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
|
|
package dnsconfigs
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestRoutes(t *testing.T) {
|
|
// 检查代号是否有空,或者代号是否重复
|
|
|
|
var codeMap = map[string]bool{} // code => true
|
|
|
|
for _, routes := range [][]*Route{
|
|
AllDefaultChinaProvinceRoutes,
|
|
AllDefaultISPRoutes,
|
|
AllDefaultWorldRegionRoutes,
|
|
} {
|
|
for _, route := range routes {
|
|
if len(route.Name) == 0 {
|
|
t.Fatal("route name should not empty:", route)
|
|
}
|
|
if len(route.AliasNames) == 0 {
|
|
t.Fatal("route alias names should not empty:", route)
|
|
}
|
|
if len(route.Code) == 0 || route.Code == "world:" {
|
|
t.Fatal("route code should not empty:", route)
|
|
}
|
|
|
|
_, ok := codeMap[route.Code]
|
|
if ok {
|
|
t.Fatal("code duplicated:", route)
|
|
}
|
|
|
|
codeMap[route.Code] = true
|
|
|
|
if strings.HasPrefix(route.Code, "world:sp:") || (strings.HasPrefix(route.Code, "world:") && route.Code != "world:UAR" && len(route.Code) != 8) {
|
|
t.Log("no shorten code:", route)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestFindDefaultRoute(t *testing.T) {
|
|
t.Log(FindDefaultRoute("isp:china_unicom"))
|
|
t.Log(FindDefaultRoute("china:province:beijing"))
|
|
t.Log(FindDefaultRoute("world:CN"))
|
|
t.Log(FindDefaultRoute("world:US"))
|
|
}
|
|
|
|
func BenchmarkFindDefaultRoute(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
_ = FindDefaultRoute("world:CN")
|
|
}
|
|
}
|