From bef5e89ec531556fbb1c19f77b8effcd59e32e9d Mon Sep 17 00:00:00 2001 From: Adam Fisk Date: Sun, 7 Jan 2024 06:51:25 -0500 Subject: [PATCH] Added test and fix for NoLookup interface --- GeoIP2-City-Test.mmdb | Bin 0 -> 22451 bytes geo.go | 9 ++++++--- geo_test.go | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 GeoIP2-City-Test.mmdb diff --git a/GeoIP2-City-Test.mmdb b/GeoIP2-City-Test.mmdb new file mode 100644 index 0000000000000000000000000000000000000000..47b5ea3a9ace9c8ae26c9637db8b4a3f5385142d GIT binary patch literal 22451 zcmZ{q2VfM{7WeP&%z%QZD4-yb33Wj!f(5LkXOob`6oMLzOR^+OlHIsPNJJkbsPtY$ z5D2}9gx-s;y>9HjrkDomQ{PkH)8|va|2=1Bi{JM}+27oA@0q#voOADt5Edb{Uxly= z(W#RV3a+jdLgkdkfL!KvW?UkK<#Qn}*HKX7FP%aqBqmQN~QhV~occeO0MU7J}blq&f6Ht+ayF|B(+(HEs@k#*4xI|F2oL2-x(>gi}Q9f_6YGD5~07)J@zFUN#9&cYKB;YlG*vG6qGOeF8D5a%MP z7r25i3K2w=UK8RaA-dEH@v;zIJ)HLn<5fae%;eWeU6ztHc$4u~xR%j7 z`~>9D)2|bjzML1wxISFO(oa})7REFBGX_M84CK2E5|+W7H-uq}6dB4zh7m3=6P6pf z$Z*tinXrriyuvaPC>EAcoOcsrG=zo1G6qN!mYZ343*%PCZH%#uag5s;cQEc`+{L(? zaSvlWZk;MD37kq~Br%d1DFoSBMxOze^l-{z=k{d?OC~F1F(xpwBPDaVWUjE>%XxW> z{78`kDk7gSF(NDymPwJ+eZq1->pc(_8a1;_7M2G&uY~as!+~Zx`RP-HrIdwb1gOdk z3CmPrDd)V3h|tA((}blmBCKLzwXnEZ!4t`=5tfI;DcslM3#Tl8VF}$h0j4h0TLB>mrmkFf) zim<#INxdd4?EftA-^iyTZ!+EzmbY2`ok-rhoEIY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PPH9a7w%0AxlZ+!w%{tG=5={SrDX+5JX1^X5Y&1=^vjQdZzZDEX*lS^S9bO^*A#pJ zfR8p1A`Li?8GxT+`6FXFtZ-}`s`ROZ;A?0CY^Q@?9C3e5^ z$3Cw&$!hhSN`H}{E&McDsnDLczn$Qifs?SZ5v88$ix1$l8XOpu;1zPU!(USEnC9`8 zJmU1quUZ?ef6T=iH!{;oKU#4WHIX(8= z(ZiGQHFIW}(^m>3FTc+H0^cxC9>$rv%+w3y2d~M7u5O#^sC4Q^zP#g&I%=moXE>_y zT299&E%=fZ*1_YhsvVkGSCP}!w4`mrg7#HS?TemoJFz0eRTFMOCp)}Ec>og$pXllV e{e=uSzLe&Vcwg+)DbwpLMVL_HbJaN;`~Dwna#OYd literal 0 HcmV?d00001 diff --git a/geo.go b/geo.go index e45a71b..3162d18 100644 --- a/geo.go +++ b/geo.go @@ -58,15 +58,18 @@ type CityLookup interface { // NoLookup is a Lookup implementation which always return empty result. type NoLookup struct{} -func (l NoLookup) CountryCode(ip net.IP) string { return "" } -func (l NoLookup) ISP(ip net.IP) string { return "" } -func (l NoLookup) ASN(ip net.IP) string { return "" } +func (l NoLookup) CountryCode(ip net.IP) string { return "" } +func (l NoLookup) ISP(ip net.IP) string { return "" } +func (l NoLookup) ASN(ip net.IP) string { return "" } +func (l NoLookup) City(ip net.IP) (string, string) { return "", "" } func (l NoLookup) Ready() <-chan struct{} { ch := make(chan struct{}) close(ch) return ch } +var _ Lookup = NoLookup{} + type lookup struct { runner *keepcurrent.Runner db atomic.Value diff --git a/geo_test.go b/geo_test.go index b944be6..013949d 100644 --- a/geo_test.go +++ b/geo_test.go @@ -90,3 +90,17 @@ func TestFromFile(t *testing.T) { testLookupISP(t, l, "127.0.0.1", "") testLookupISP(t, l, "1.1.1.1", "") } + +func TestLookupCity(t *testing.T) { + filePath := "./GeoIP2-City-Test.mmdb" + l, err := FromFile(filePath) + assert.NoError(t, err) + + testLookupCity(t, l, "81.2.69.142", "London", "United Kingdom") +} + +func testLookupCity(t *testing.T, l Lookup, ip string, expectedCity, expectedCountry string) { + city, country := l.City(net.ParseIP(ip)) + assert.Equal(t, expectedCity, city) + assert.Equal(t, expectedCountry, country) +}