d44970a43f
* chore: update all workflows to use go1.17.2 See https://github.com/ooni/probe/issues/1815 * chore: update all dependencies See https://github.com/ooni/probe/issues/1815 * chore: run `go generate` See https://github.com/ooni/probe/issues/1815 * chore: update the user-agent Part of https://github.com/ooni/probe/issues/1815 * Set version to 3.12.0-alpha Part of https://github.com/ooni/probe/issues/1815 * fix: update to ooni/probe-assets@v0.5.0 This overcomes https://github.com/ooni/probe/issues/1836 in the CLI and, while there, let us also make maxminddb tests stricter. * fix(QA/Dockerfile): build using go1.17 See https://github.com/ooni/probe-cli/pull/547#issuecomment-947760839 * chore(mk): use go1.17.2 Part of https://github.com/ooni/probe/issues/1815 * fix(codeql): always run for master Otherwise we see a warning that there is no CodeQL information available for the base branch and this is sub-optimal. Part of https://github.com/ooni/probe/issues/1815
52 lines
967 B
Go
52 lines
967 B
Go
package geolocate
|
|
|
|
import "testing"
|
|
|
|
const ipAddr = "8.8.8.8"
|
|
|
|
func TestLookupASN(t *testing.T) {
|
|
asn, org, err := LookupASN(ipAddr)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if asn != 15169 {
|
|
t.Fatal("unexpected ASN value", asn)
|
|
}
|
|
if org != "Google LLC" {
|
|
t.Fatal("unexpected org value", org)
|
|
}
|
|
}
|
|
|
|
func TestLookupASNInvalidIP(t *testing.T) {
|
|
asn, org, err := LookupASN("xxx")
|
|
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) {
|
|
cc, err := (mmdbLookupper{}).LookupCC(ipAddr)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cc != "US" {
|
|
t.Fatal("invalid country code", cc)
|
|
}
|
|
}
|
|
|
|
func TestLookupCCInvalidIP(t *testing.T) {
|
|
cc, err := (mmdbLookupper{}).LookupCC("xxx")
|
|
if err == nil {
|
|
t.Fatal("expected an error here")
|
|
}
|
|
if cc != DefaultProbeCC {
|
|
t.Fatal("expected an empty cc")
|
|
}
|
|
}
|