test: add a test with ipv6 address
This commit is contained in:
parent
a7ad11c2e7
commit
c99890eda5
|
@ -34,7 +34,6 @@ import java.util.zip.GZIPInputStream;
|
|||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
public class GeoIpProcessorTests extends ESTestCase {
|
||||
|
||||
|
@ -65,6 +64,34 @@ public class GeoIpProcessorTests extends ESTestCase {
|
|||
assertThat(geoData.get("location"), equalTo(location));
|
||||
}
|
||||
|
||||
public void testCity_withIpV6() throws Exception {
|
||||
InputStream database = getDatabaseFileInputStream("/GeoLite2-City.mmdb.gz");
|
||||
GeoIpProcessor processor = new GeoIpProcessor(randomAsciiOfLength(10), "source_field",
|
||||
new DatabaseReader.Builder(database).build(), "target_field", EnumSet.allOf(GeoIpProcessor.Property.class));
|
||||
|
||||
String address = "2602:306:33d3:8000::3257:9652";
|
||||
Map<String, Object> document = new HashMap<>();
|
||||
document.put("source_field", address);
|
||||
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
|
||||
processor.execute(ingestDocument);
|
||||
|
||||
assertThat(ingestDocument.getSourceAndMetadata().get("source_field"), equalTo(address));
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> geoData = (Map<String, Object>) ingestDocument.getSourceAndMetadata().get("target_field");
|
||||
assertThat(geoData.size(), equalTo(8));
|
||||
assertThat(geoData.get("ip"), equalTo(address));
|
||||
assertThat(geoData.get("country_iso_code"), equalTo("US"));
|
||||
assertThat(geoData.get("country_name"), equalTo("United States"));
|
||||
assertThat(geoData.get("continent_name"), equalTo("North America"));
|
||||
assertThat(geoData.get("region_name"), equalTo("Florida"));
|
||||
assertThat(geoData.get("city_name"), equalTo("Hollywood"));
|
||||
assertThat(geoData.get("timezone"), equalTo("America/New_York"));
|
||||
Map<String, Object> location = new HashMap<>();
|
||||
location.put("lat", 26.0252d);
|
||||
location.put("lon", -80.296d);
|
||||
assertThat(geoData.get("location"), equalTo(location));
|
||||
}
|
||||
|
||||
public void testCityWithMissingLocation() throws Exception {
|
||||
InputStream database = getDatabaseFileInputStream("/GeoLite2-City.mmdb.gz");
|
||||
GeoIpProcessor processor = new GeoIpProcessor(randomAsciiOfLength(10), "source_field",
|
||||
|
@ -149,7 +176,7 @@ public class GeoIpProcessorTests extends ESTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
static InputStream getDatabaseFileInputStream(String path) throws IOException {
|
||||
private static InputStream getDatabaseFileInputStream(String path) throws IOException {
|
||||
return new GZIPInputStream(GeoIpProcessor.class.getResourceAsStream(path));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue