whatismyip/service/geo_test.go

34 lines
620 B
Go
Raw Normal View History

2021-11-10 19:06:12 +00:00
package service
import (
2025-01-02 19:13:41 +00:00
"context"
2021-11-10 19:06:12 +00:00
"net"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
2025-01-02 19:13:41 +00:00
var geoSvc *Geo
2021-11-10 19:06:12 +00:00
func TestMain(m *testing.M) {
2025-01-02 19:13:41 +00:00
geoSvc, _ = NewGeo(context.Background(), "../test/GeoIP2-City-Test.mmdb", "../test/GeoLite2-ASN-Test.mmdb")
2021-11-10 19:06:12 +00:00
os.Exit(m.Run())
}
func TestCityLookup(t *testing.T) {
2025-01-02 19:13:41 +00:00
c := geoSvc.LookUpCity(net.ParseIP("error"))
2021-11-10 19:06:12 +00:00
assert.Nil(t, c)
2025-01-02 19:13:41 +00:00
c = geoSvc.LookUpCity(net.ParseIP("1.1.1.1"))
2021-11-10 19:06:12 +00:00
assert.NotNil(t, c)
}
func TestASNLookup(t *testing.T) {
2025-01-02 19:13:41 +00:00
a := geoSvc.LookUpASN(net.ParseIP("error"))
2021-11-10 19:06:12 +00:00
assert.Nil(t, a)
2025-01-02 19:13:41 +00:00
a = geoSvc.LookUpASN(net.ParseIP("1.1.1.1"))
2021-11-10 19:06:12 +00:00
assert.NotNil(t, a)
}