26 lines
657 B
Go
26 lines
657 B
Go
package geoip
|
|
|
|
import (
|
|
"net/netip"
|
|
"testing"
|
|
)
|
|
|
|
func TestLookupWithoutDB(t *testing.T) {
|
|
var l *Lookup
|
|
if r := l.Lookup(netip.MustParseAddr("8.8.8.8")); r.Configured || r.Country != "" {
|
|
t.Fatalf("unexpected result %+v", r)
|
|
}
|
|
if r := l.Lookup(netip.MustParseAddr("10.1.2.3")); r.Scope != "private" {
|
|
t.Fatalf("want private scope, got %+v", r)
|
|
}
|
|
if r := l.Lookup(netip.MustParseAddr("::ffff:127.0.0.1")); r.Scope != "loopback" || r.IP != "127.0.0.1" {
|
|
t.Fatalf("want unmapped loopback, got %+v", r)
|
|
}
|
|
}
|
|
|
|
func TestOpenEmpty(t *testing.T) {
|
|
if l, err := Open("", ""); l != nil || err != nil {
|
|
t.Fatalf("want nil,nil got %v,%v", l, err)
|
|
}
|
|
}
|