[优化] 新增 GeoIP 测试功能,更新相关 API 路由和前端组件

This commit is contained in:
ryan
2026-03-15 14:43:28 +08:00
parent 5bb25d2203
commit 640dd6c82c
9 changed files with 327 additions and 8 deletions
+18
View File
@@ -79,3 +79,21 @@ func TestIsValidProvider(t *testing.T) {
}
}
}
func TestLookupGeoInfoWithProviderUsesTemporaryProvider(t *testing.T) {
previousFactory := providerFactory
providerFactory = func(provider string) (GeoIPService, error) {
return &fakeProvider{}, nil
}
defer func() {
providerFactory = previousFactory
}()
info, err := LookupGeoInfoWithProvider("ipinfo", net.ParseIP("8.8.8.8"))
if err != nil {
t.Fatalf("expected lookup to succeed, got %v", err)
}
if info == nil || info.ISOCode != "CN" || info.Name != "China" {
t.Fatalf("unexpected geo info: %#v", info)
}
}