mirror of
https://github.com/dcarrillo/whatismyip.git
synced 2025-07-04 09:19:25 +00:00
first commit
This commit is contained in:
36
service/geo_test.go
Normal file
36
service/geo_test.go
Normal file
@ -0,0 +1,36 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/dcarrillo/whatismyip/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
models.Setup("../test/GeoIP2-City-Test.mmdb", "../test/GeoLite2-ASN-Test.mmdb")
|
||||
defer models.CloseDBs()
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestCityLookup(t *testing.T) {
|
||||
ip := Geo{IP: net.ParseIP("error")}
|
||||
c := ip.LookUpCity()
|
||||
assert.Nil(t, c)
|
||||
|
||||
ip = Geo{IP: net.ParseIP("1.1.1.1")}
|
||||
c = ip.LookUpCity()
|
||||
assert.NotNil(t, c)
|
||||
}
|
||||
|
||||
func TestASNLookup(t *testing.T) {
|
||||
ip := Geo{IP: net.ParseIP("error")}
|
||||
a := ip.LookUpASN()
|
||||
assert.Nil(t, a)
|
||||
|
||||
ip = Geo{IP: net.ParseIP("1.1.1.1")}
|
||||
a = ip.LookUpASN()
|
||||
assert.NotNil(t, a)
|
||||
}
|
Reference in New Issue
Block a user