Skip to content

Commit

Permalink
Add a test about the relationships between databases
Browse files Browse the repository at this point in the history
and add the missing CONNECTION_TYPE property that I forgot to add to
Database.Enterprise.
  • Loading branch information
joegallo committed May 15, 2024
1 parent 60f7189 commit b05950b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ enum Database {
Property.ISP,
Property.ISP_ORGANIZATION_NAME,
Property.MOBILE_COUNTRY_CODE,
Property.MOBILE_NETWORK_CODE
Property.MOBILE_NETWORK_CODE,
Property.CONNECTION_TYPE
),
Set.of(
Property.COUNTRY_ISO_CODE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.maxmind.geoip2.DatabaseReader;

import org.elasticsearch.common.CheckedSupplier;
import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.core.PathUtils;
import org.elasticsearch.ingest.IngestDocument;
import org.elasticsearch.ingest.RandomDocumentPicks;
Expand All @@ -29,6 +30,7 @@

import static org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.is;
Expand All @@ -38,6 +40,24 @@ public class GeoIpProcessorTests extends ESTestCase {

private static final Set<Property> ALL_PROPERTIES = Set.of(Property.values());

public void testDatabasePropertyInvariants() {
// the city database is like a specialization of the country database
assertThat(Sets.difference(Database.Country.properties(), Database.City.properties()), is(empty()));
assertThat(Sets.difference(Database.Country.defaultProperties(), Database.City.defaultProperties()), is(empty()));

// the isp database is like a specialization of the asn database
assertThat(Sets.difference(Database.Asn.properties(), Database.Isp.properties()), is(empty()));
assertThat(Sets.difference(Database.Asn.defaultProperties(), Database.Isp.defaultProperties()), is(empty()));

// the enterprise database is like everything joined together
for (Database type : Database.values()) {
assertThat(Sets.difference(type.properties(), Database.Enterprise.properties()), is(empty()));
}
// but in terms of the default fields, it's like a drop-in replacement for the city database
// n.b. this is just a choice we decided to make here at Elastic
assertThat(Database.Enterprise.defaultProperties(), equalTo(Database.City.defaultProperties()));
}

public void testCity() throws Exception {
GeoIpProcessor processor = new GeoIpProcessor(
randomAlphaOfLength(10),
Expand Down

0 comments on commit b05950b

Please sign in to comment.