2021-01-25 16:40:03 +08:00
|
|
|
package regions
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
|
_ "github.com/iwind/TeaGo/bootstrap"
|
|
|
|
|
"github.com/iwind/TeaGo/dbs"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
2022-08-13 23:55:48 +08:00
|
|
|
func TestRegionCountryDAO_FindCountryIdWithName(t *testing.T) {
|
|
|
|
|
dbs.NotifyReady()
|
|
|
|
|
|
|
|
|
|
for _, name := range []string{
|
|
|
|
|
"中国",
|
|
|
|
|
"中华人民共和国",
|
|
|
|
|
"美国",
|
|
|
|
|
"美利坚合众国",
|
|
|
|
|
"美利坚",
|
|
|
|
|
} {
|
|
|
|
|
countryId, err := SharedRegionCountryDAO.FindCountryIdWithName(nil, name)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
t.Log(name, ":", countryId)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-25 16:40:03 +08:00
|
|
|
func TestRegionCountryDAO_FindCountryIdWithCountryNameCacheable(t *testing.T) {
|
|
|
|
|
dbs.NotifyReady()
|
|
|
|
|
|
|
|
|
|
for i := 0; i < 5; i++ {
|
2022-08-13 23:55:48 +08:00
|
|
|
var now = time.Now()
|
2021-01-25 16:40:03 +08:00
|
|
|
countryId, err := SharedRegionCountryDAO.FindCountryIdWithNameCacheable(nil, "中国")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
t.Log("countryId", countryId, time.Since(now).Seconds()*1000, "ms")
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-13 23:55:48 +08:00
|
|
|
|
|
|
|
|
func TestRegionCountryDAO_FindSimilarCountries(t *testing.T) {
|
|
|
|
|
dbs.NotifyReady()
|
|
|
|
|
|
|
|
|
|
var tx *dbs.Tx
|
|
|
|
|
countries, err := SharedRegionCountryDAO.FindAllCountries(tx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, countryName := range []string{"中国", "布基纳法索", "哥伦比亚", "德意志共和国", "美利坚", "刚果金"} {
|
|
|
|
|
t.Log("====" + countryName + "====")
|
|
|
|
|
var countries = SharedRegionCountryDAO.FindSimilarCountries(countries, countryName, 5)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
for _, country := range countries {
|
|
|
|
|
t.Log(country.Name, country.AllCodes())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|