refactor: spin geoipx off geolocate (#893)
A bunch of packages (including oohelperd) just need the ability to use MaxMind-like databases. They don't need the additional functionality implemented by the geolocate package. Such a package, in fact, is mostly (if not only) needed by the engine package. Therefore, move code to query MaxMind-like databases to a separate package, and avoid depending on geolocate in all the packages for which it's sufficient to use geoipx. Part of https://github.com/ooni/probe/issues/2240
This commit is contained in:
parent
1e7384d1cc
commit
110a11828b
23 changed files with 224 additions and 211 deletions
59
internal/geoipx/geoipx_test.go
Normal file
59
internal/geoipx/geoipx_test.go
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
package geoipx
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
)
|
||||
|
||||
const ipAddr = "8.8.8.8"
|
||||
|
||||
func TestLookupASN(t *testing.T) {
|
||||
t.Run("with valid IP address", func(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)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("with invalid IP address", func(t *testing.T) {
|
||||
asn, org, err := LookupASN("xxx")
|
||||
if err == nil {
|
||||
t.Fatal("expected an error here")
|
||||
}
|
||||
if asn != model.DefaultProbeASN {
|
||||
t.Fatal("expected a zero ASN")
|
||||
}
|
||||
if org != model.DefaultProbeNetworkName {
|
||||
t.Fatal("expected an empty org")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestLookupCC(t *testing.T) {
|
||||
t.Run("with valid IP address", func(t *testing.T) {
|
||||
cc, err := LookupCC(ipAddr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cc != "US" {
|
||||
t.Fatal("invalid country code", cc)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("with invalid IP address", func(t *testing.T) {
|
||||
cc, err := LookupCC("xxx")
|
||||
if err == nil {
|
||||
t.Fatal("expected an error here")
|
||||
}
|
||||
if cc != model.DefaultProbeCC {
|
||||
t.Fatal("expected an empty cc")
|
||||
}
|
||||
})
|
||||
}
|
||||
Loading…
Reference in a new issue