github.com/Jeffail/benthos/v3@v3.65.0/internal/impl/maxmind/bloblang_geoip_test.go (about) 1 package maxmind 2 3 import ( 4 "testing" 5 6 "github.com/Jeffail/benthos/v3/public/bloblang" 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestGeoIPCity(t *testing.T) { 12 testCases := []struct { 13 name string 14 input string 15 exp interface{} 16 }{ 17 { 18 name: "geoip city", 19 input: `root = "81.2.69.192".geoip_city("./testdata/GeoIP2-City-Test.mmdb").City.Names.en`, 20 exp: "London", 21 }, 22 { 23 name: "geoip country", 24 input: `root = "2001:220::80".geoip_country("./testdata/GeoIP2-Country-Test.mmdb").Country.Names.en`, 25 exp: "South Korea", 26 }, 27 { 28 name: "geoip ASN", 29 input: `root = "214.0.0.0".geoip_asn("./testdata/GeoLite2-ASN-Test.mmdb").AutonomousSystemOrganization`, 30 exp: "DoD Network Information Center", 31 }, 32 { 33 name: "geoip enterprise", 34 input: `root = "149.101.100.0".geoip_enterprise("./testdata/GeoIP2-Enterprise-Test.mmdb").Traits.ISP`, 35 exp: "Verizon Wireless", 36 }, 37 { 38 name: "geoip anonymous IP", 39 input: `root = "81.2.69.0".geoip_anonymous_ip("./testdata/GeoIP2-Anonymous-IP-Test.mmdb").IsTorExitNode`, 40 exp: true, 41 }, 42 { 43 name: "geoip connection type", 44 input: `root = "207.179.48.0".geoip_connection_type("./testdata/GeoIP2-Connection-Type-Test.mmdb").ConnectionType`, 45 exp: "Cellular", 46 }, 47 { 48 name: "geoip domain", 49 input: `root = "89.95.192.0".geoip_domain("./testdata/GeoIP2-Domain-Test.mmdb").Domain`, 50 exp: "bbox.fr", 51 }, 52 { 53 name: "geoip ISP", 54 input: `root = "12.87.120.0".geoip_isp("./testdata/GeoIP2-ISP-Test.mmdb").ISP`, 55 exp: "AT&T Services", 56 }, 57 } 58 59 for _, test := range testCases { 60 test := test 61 t.Run(test.name, func(t *testing.T) { 62 exec, err := bloblang.Parse(test.input) 63 require.NoError(t, err) 64 65 res, err := exec.Query(nil) 66 require.NoError(t, err) 67 68 assert.Equal(t, test.exp, res) 69 }) 70 } 71 }