12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package geodb_test
- import (
- "testing"
- "imuslab.com/zoraxy/mod/geodb"
- )
- func TestResolveCountryCodeFromIP(t *testing.T) {
-
- store, err := geodb.NewGeoDb(nil, &geodb.StoreOptions{
- false,
- false,
- })
- if err != nil {
- t.Errorf("error creating store: %v", err)
- return
- }
-
- knownIpCountryMap := [][]string{
- {"3.224.220.101", "US"},
- {"176.113.115.113", "RU"},
- {"65.21.233.213", "FI"},
- {"94.23.207.193", "FR"},
- }
- for _, testcase := range knownIpCountryMap {
- ip := testcase[0]
- expected := testcase[1]
- info, err := store.ResolveCountryCodeFromIP(ip)
- if err != nil {
- t.Errorf("error resolving country code for IP %s: %v", ip, err)
- return
- }
- if info.CountryIsoCode != expected {
- t.Errorf("expected country code %s, but got %s for IP %s", expected, info.CountryIsoCode, ip)
- }
- }
-
- ip := "127.0.0.1"
- expected := ""
- info, err := store.ResolveCountryCodeFromIP(ip)
- if err != nil {
- t.Errorf("error resolving country code for IP %s: %v", ip, err)
- return
- }
- if info.CountryIsoCode != expected {
- t.Errorf("expected country code %s, but got %s for IP %s", expected, info.CountryIsoCode, ip)
- }
- }
|