1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- package geodb_test
- import (
- "testing"
- "imuslab.com/zoraxy/mod/geodb"
- )
- func TestResolveCountryCodeFromIP(t *testing.T) {
-
- store, err := geodb.NewGeoDb(nil, &geodb.StoreOptions{
- false,
- true,
- })
- 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"},
- {"77.131.21.232", "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)
- }
- }
|