1 Star 0 Fork 0

eecjimmy / go-location

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
db_test.go 903 Bytes
一键复制 编辑 原始数据 按行查看 历史
eecjimmy 提交于 2021-07-22 14:08 . first commit
package ip
import (
"github.com/stretchr/testify/assert"
"log"
"testing"
)
var d *database
func db() *database {
if d != nil {
return d
}
d, e := getDB()
if e != nil {
log.Fatal(e)
}
return d
}
func TestInternal(t *testing.T) {
loc, e := db().query("192.168.1.1")
if e != nil {
t.Fail()
return
}
assert.Equal(t, "局域网", loc.Country)
assert.Equal(t, "192.168.0.0", loc.BeginIP)
assert.Equal(t, "192.168.0.0", loc.BeginIP)
}
func TestChina(t *testing.T) {
loc, e := db().query("47.105.173.69")
if e != nil {
t.Fail()
return
}
assert.Equal(t, "山东省青岛市", loc.Country)
assert.Equal(t, "阿里云", loc.Area)
}
func TestForeign(t *testing.T) {
loc, e := db().query("8.8.8.8")
if e != nil {
t.Fail()
return
}
assert.Equal(t, "美国", loc.Country)
assert.Equal(t, "加利福尼亚州圣克拉拉县山景市谷歌公司DNS服务器", loc.Area)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/eecjimmy/go-location.git
git@gitee.com:eecjimmy/go-location.git
eecjimmy
go-location
go-location
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891