mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-12 06:24:10 +01:00
Now:
```
goos: linux
goarch: amd64
pkg: akvorado/orchestrator/geoip
cpu: AMD Ryzen 7 PRO 6850U with Radeon Graphics
BenchmarkIterDatabase/ASN-16 3376 457.0 ns/entry
BenchmarkIterDatabase/GeoIP-16 2410 754.5 ns/entry
```
Before 0a10764cc9:
```
goos: linux
goarch: amd64
pkg: akvorado/orchestrator/geoip
cpu: AMD Ryzen 7 PRO 6850U with Radeon Graphics
BenchmarkIterDatabase/ASN-16 2863 609.3 ns/entry
BenchmarkIterDatabase/GeoIP-16 3286 719.3 ns/entry
```
I was hoping for a bit more!
46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
// SPDX-FileCopyrightText: 2022 Free Mobile
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
//go:build !release
|
|
|
|
package geoip
|
|
|
|
import (
|
|
"path"
|
|
"path/filepath"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"akvorado/common/daemon"
|
|
"akvorado/common/helpers"
|
|
"akvorado/common/reporter"
|
|
)
|
|
|
|
// NewMock creates a GeoIP component usable for testing. It is already
|
|
// started. It panics if there is an issue. Data of both databases are
|
|
// available here:
|
|
// - https://github.com/maxmind/MaxMind-DB/blob/main/source-data/GeoLite2-ASN-Test.json
|
|
// - https://github.com/maxmind/MaxMind-DB/blob/main/source-data/GeoLite2-Country-Test.json
|
|
func NewMock(t testing.TB, r *reporter.Reporter, withData bool) *Component {
|
|
t.Helper()
|
|
config := DefaultConfiguration()
|
|
_, src, _, _ := runtime.Caller(0)
|
|
if withData {
|
|
config.GeoDatabase = []string{
|
|
filepath.Join(path.Dir(src), "testdata", "GeoLite2-City-Test.mmdb"),
|
|
filepath.Join(path.Dir(src), "testdata", "ip_country_asn_sample.mmdb"),
|
|
filepath.Join(path.Dir(src), "testdata", "ip_geolocation_sample.mmdb"),
|
|
}
|
|
config.ASNDatabase = []string{
|
|
filepath.Join(path.Dir(src), "testdata", "GeoLite2-ASN-Test.mmdb"),
|
|
filepath.Join(path.Dir(src), "testdata", "ip_country_asn_sample.mmdb"),
|
|
}
|
|
}
|
|
c, err := New(r, config, Dependencies{Daemon: daemon.NewMock(t)})
|
|
if err != nil {
|
|
t.Fatalf("New() error:\n%+s", err)
|
|
}
|
|
helpers.StartStop(t, c)
|
|
return c
|
|
}
|