Files
geo/server/internal/shared/ipregion/ip_region_test.go
T
root 1eae6fb6d4
Deployment Config CI / Deployment Config (push) Successful in 29s
Frontend CI / Frontend (push) Successful in 4m4s
Backend CI / Backend (push) Failing after 7m12s
feat(questions): make brand questions the primary monitoring & template axis
- add /questions/combination-fill endpoint with AI-driven, IP-region-aware matrix fill
- extract ip2region resolver from ops/app into shared/ipregion for cross-service use
- thread question_id filter through dashboard composite, citation summary, and collect-now
- switch template wizard from keyword inputs to brand-question selection (primary + supplemental)
- pass brand_question and supplemental_questions through assist/title/outline prompts
- add AiWaitingModal + 45s client timeout and request_timeout error mapping for long AI flows

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 15:59:39 +08:00

53 lines
1.4 KiB
Go

package ipregion
import "testing"
func TestResolverLookupSpecialAddresses(t *testing.T) {
resolver := &Resolver{}
tests := []struct {
name string
ip string
want string
}{
{name: "ipv4 loopback", ip: "127.0.0.1", want: "本机"},
{name: "ipv6 loopback", ip: "::1", want: "本机"},
{name: "private network", ip: "192.168.1.10", want: "内网IP"},
{name: "host port", ip: "10.0.0.8:443", want: "内网IP"},
{name: "invalid", ip: "not-an-ip", want: ""},
{name: "public disabled", ip: "8.8.8.8", want: ""},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := resolver.Lookup(tt.ip); got != tt.want {
t.Fatalf("Lookup(%q) = %q, want %q", tt.ip, got, tt.want)
}
})
}
}
func TestResolverLookupFromXDB(t *testing.T) {
resolver, err := NewResolver("", "", nil)
if err != nil {
t.Fatalf("NewResolver() error = %v", err)
}
defer resolver.Close()
if got := resolver.Lookup("8.8.8.8"); got == "" {
t.Fatal("Lookup(8.8.8.8) returned empty region")
}
}
func TestResolverExternalPathFallsBackToEmbedWhenMissing(t *testing.T) {
resolver, err := NewResolver("/path/not/exist/ip2region_v4.xdb", "/path/not/exist/ip2region_v6.xdb", nil)
if err != nil {
t.Fatalf("NewResolver() error = %v", err)
}
defer resolver.Close()
if got := resolver.Lookup("8.8.8.8"); got == "" {
t.Fatal("Lookup(8.8.8.8) returned empty region")
}
}