Fix tests and linters
This commit is contained in:
@@ -58,7 +58,7 @@ func (ub *updateBroadcaster) ReplaceDatabase(db *geoIPDB) {
|
||||
defer ub.rw.Unlock()
|
||||
|
||||
if ub.db != nil {
|
||||
ub.db.Close()
|
||||
_ = ub.db.Close()
|
||||
}
|
||||
ub.db = db
|
||||
ub.notifyWaiters()
|
||||
@@ -101,7 +101,7 @@ type updateWorker struct {
|
||||
// waiting nil is returned.
|
||||
func (upd *updateWorker) GetReader(v6 bool, wait bool) *maxminddb.Reader {
|
||||
// check which updateBroadcaster we need to use
|
||||
var ub *updateBroadcaster = &upd.v4
|
||||
ub := &upd.v4
|
||||
if v6 {
|
||||
ub = &upd.v6
|
||||
}
|
||||
|
||||
@@ -5,8 +5,9 @@ import (
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/safing/portbase/utils"
|
||||
"github.com/umahmood/haversine"
|
||||
|
||||
"github.com/safing/portbase/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -27,6 +28,7 @@ type Location struct {
|
||||
AutonomousSystemOrganization string `maxminddb:"autonomous_system_organization"`
|
||||
}
|
||||
|
||||
// Coordinates holds geographic coordinates and their estimated accuracy.
|
||||
type Coordinates struct {
|
||||
AccuracyRadius uint16 `maxminddb:"accuracy_radius"`
|
||||
Latitude float64 `maxminddb:"latitude"`
|
||||
@@ -199,6 +201,8 @@ var unknownASOrgNames = []string{
|
||||
"undefined", // Programmatic unknown value.
|
||||
}
|
||||
|
||||
// ASOrgUnknown return whether the given AS Org string actually is meant to
|
||||
// mean that the AS Org is unknown.
|
||||
func ASOrgUnknown(asOrg string) bool {
|
||||
return utils.StringInSlice(
|
||||
unknownASOrgNames,
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
)
|
||||
|
||||
func TestPrimitiveNetworkProximity(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ip4_1 := net.ParseIP("1.1.1.1")
|
||||
ip4_2 := net.ParseIP("1.1.1.2")
|
||||
ip4_3 := net.ParseIP("255.255.255.0")
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
)
|
||||
|
||||
func TestLocationLookup(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ip1 := net.ParseIP("81.2.69.142")
|
||||
loc1, err := GetLocation(ip1)
|
||||
if err != nil {
|
||||
@@ -53,8 +55,8 @@ func TestLocationLookup(t *testing.T) {
|
||||
dist3 := loc1.EstimateNetworkProximity(loc3)
|
||||
dist4 := loc1.EstimateNetworkProximity(loc4)
|
||||
|
||||
t.Logf("proximity %s <> %s: %d", ip1, ip2, dist1)
|
||||
t.Logf("proximity %s <> %s: %d", ip2, ip3, dist2)
|
||||
t.Logf("proximity %s <> %s: %d", ip1, ip3, dist3)
|
||||
t.Logf("proximity %s <> %s: %d", ip1, ip4, dist4)
|
||||
t.Logf("proximity %s <> %s: %.2f", ip1, ip2, dist1)
|
||||
t.Logf("proximity %s <> %s: %.2f", ip2, ip3, dist2)
|
||||
t.Logf("proximity %s <> %s: %.2f", ip1, ip3, dist3)
|
||||
t.Logf("proximity %s <> %s: %.2f", ip1, ip4, dist4)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user