package geodb_test import ( "testing" "imuslab.com/zoraxy/mod/geodb" ) func TestResolveCountryCodeFromIP(t *testing.T) { // Create a new store store, err := geodb.NewGeoDb(nil) if err != nil { t.Errorf("error creating store: %v", err) return } /* result, err := store.Search("7.8.8.8") if err != nil { t.Error(err.Error()) return } fmt.Println(">> ", result, err) return */ // Test an IP address that should return a valid country code ip := "8.8.8.8" expected := "US" 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) } // Test an IP address that should return an empty country code 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) } }