initial commit
This commit is contained in:
commit
885e7d6e02
22 changed files with 3001 additions and 0 deletions
59
internal/geo/geo_test.go
Normal file
59
internal/geo/geo_test.go
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
package geo
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewGeoLookup_NilPath(t *testing.T) {
|
||||
gl, err := NewGeoLookup("")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if gl == nil {
|
||||
t.Fatal("expected non-nil GeoLookup")
|
||||
}
|
||||
if gl.IsEnabled() {
|
||||
t.Error("expected IsEnabled() = false for empty path")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeoLookup_LookupWithNoDb(t *testing.T) {
|
||||
gl, _ := NewGeoLookup("")
|
||||
result := gl.Lookup(net.ParseIP("8.8.8.8"))
|
||||
if result != nil {
|
||||
t.Errorf("expected nil result when no db, got %+v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeoLookup_LookupNilIP(t *testing.T) {
|
||||
gl, _ := NewGeoLookup("")
|
||||
result := gl.Lookup(nil)
|
||||
if result != nil {
|
||||
t.Errorf("expected nil result for nil IP, got %+v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewGeoLookup_InvalidPath(t *testing.T) {
|
||||
_, err := NewGeoLookup("/nonexistent/path/GeoLite2-City.mmdb")
|
||||
if err == nil {
|
||||
t.Error("expected error for nonexistent db file, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeoPoint_Fields(t *testing.T) {
|
||||
gp := GeoPoint{
|
||||
IP: "1.2.3.4",
|
||||
Lat: 37.751,
|
||||
Lon: -97.822,
|
||||
Country: "United States",
|
||||
CountryCode: "US",
|
||||
Count: 42,
|
||||
}
|
||||
if gp.IP != "1.2.3.4" {
|
||||
t.Errorf("IP = %q", gp.IP)
|
||||
}
|
||||
if gp.Count != 42 {
|
||||
t.Errorf("Count = %d", gp.Count)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue