mirror of
https://github.com/nxtrace/NTrace-core.git
synced 2026-11-28 07:35:37 +00:00
- 将公共 data_provider 统一为 NextTrace-API,并保留旧别名输入兼容 - 按 v3/v4 语义重命名内部实现并保留 Deprecated Go 包装 - 同步 CLI、Web、MCP、文档及输出规范化测试
63 lines
1.8 KiB
Go
63 lines
1.8 KiB
Go
package printer
|
|
|
|
import (
|
|
"io"
|
|
"net"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/nxtrace/NTrace-core/ipgeo"
|
|
"github.com/nxtrace/NTrace-core/trace"
|
|
)
|
|
|
|
func TestApplyLangSettingRecognizesNextTraceAPIProviderAliases(t *testing.T) {
|
|
for _, source := range []string{ipgeo.NextTraceAPIProvider, "LeoMoeAPI"} {
|
|
hop := &trace.Hop{Geo: &ipgeo.IPGeoData{Source: source}}
|
|
applyLangSetting(hop)
|
|
if hop.Geo.Country != "未知" || hop.Geo.CountryEn != "Unknown" {
|
|
t.Fatalf("source %q produced country %q/%q, want NextTrace API unknown labels", source, hop.Geo.Country, hop.Geo.CountryEn)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestApplyLangSettingKeepsOtherProviderNetworkError(t *testing.T) {
|
|
hop := &trace.Hop{Geo: &ipgeo.IPGeoData{Source: "IPInfo"}}
|
|
applyLangSetting(hop)
|
|
if hop.Geo.Country != "网络故障" || hop.Geo.CountryEn != "Network Error" {
|
|
t.Fatalf("country = %q/%q, want network error labels", hop.Geo.Country, hop.Geo.CountryEn)
|
|
}
|
|
}
|
|
|
|
func TestPrintTraceRouteNavCanonicalizesLegacyNextTraceAPIProvider(t *testing.T) {
|
|
originalStdout := os.Stdout
|
|
readPipe, writePipe, err := os.Pipe()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
os.Stdout = writePipe
|
|
t.Cleanup(func() {
|
|
os.Stdout = originalStdout
|
|
_ = readPipe.Close()
|
|
_ = writePipe.Close()
|
|
})
|
|
|
|
PrintTraceRouteNav(net.ParseIP("1.1.1.1"), "1.1.1.1", "LeoMoeAPI", 30, 28, "", "icmp")
|
|
if err := writePipe.Close(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
os.Stdout = originalStdout
|
|
output, err := io.ReadAll(readPipe)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
lines := strings.Split(strings.TrimSuffix(string(output), "\n"), "\n")
|
|
if len(lines) == 0 || lines[0] != "IP Geo Data Provider: NextTrace-API" {
|
|
t.Fatalf("provider output line = %q, want canonical NextTrace API name", lines[0])
|
|
}
|
|
if strings.Contains(strings.ToUpper(string(output)), "LEOMOE") {
|
|
t.Fatalf("output leaks legacy provider name: %q", output)
|
|
}
|
|
}
|