2021-02-02 12:05:47 +01:00
|
|
|
package geolocate
|
|
|
|
|
2021-04-01 16:57:31 +02:00
|
|
|
import "testing"
|
2021-02-02 12:05:47 +01:00
|
|
|
|
2021-10-20 18:16:40 +02:00
|
|
|
const ipAddr = "8.8.8.8"
|
2021-02-02 12:05:47 +01:00
|
|
|
|
|
|
|
func TestLookupASN(t *testing.T) {
|
2021-04-01 16:57:31 +02:00
|
|
|
asn, org, err := LookupASN(ipAddr)
|
2021-02-02 12:05:47 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-10-20 18:16:40 +02:00
|
|
|
if asn != 15169 {
|
|
|
|
t.Fatal("unexpected ASN value", asn)
|
2021-02-02 12:05:47 +01:00
|
|
|
}
|
2021-10-20 18:16:40 +02:00
|
|
|
if org != "Google LLC" {
|
|
|
|
t.Fatal("unexpected org value", org)
|
2021-02-02 12:05:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLookupASNInvalidIP(t *testing.T) {
|
2021-04-01 16:57:31 +02:00
|
|
|
asn, org, err := LookupASN("xxx")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("expected an error here")
|
|
|
|
}
|
|
|
|
if asn != DefaultProbeASN {
|
|
|
|
t.Fatal("expected a zero ASN")
|
|
|
|
}
|
|
|
|
if org != DefaultProbeNetworkName {
|
|
|
|
t.Fatal("expected an empty org")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLookupCC(t *testing.T) {
|
2021-04-01 16:57:31 +02:00
|
|
|
cc, err := (mmdbLookupper{}).LookupCC(ipAddr)
|
2021-02-02 12:05:47 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-10-20 18:16:40 +02:00
|
|
|
if cc != "US" {
|
|
|
|
t.Fatal("invalid country code", cc)
|
2021-02-02 12:05:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLookupCCInvalidIP(t *testing.T) {
|
2021-04-01 16:57:31 +02:00
|
|
|
cc, err := (mmdbLookupper{}).LookupCC("xxx")
|
2021-02-02 12:05:47 +01:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("expected an error here")
|
|
|
|
}
|
|
|
|
if cc != DefaultProbeCC {
|
|
|
|
t.Fatal("expected an empty cc")
|
|
|
|
}
|
|
|
|
}
|