Skip to content

Commit 04989e5

Browse files
committed
[test] Covered all the databases used in handleEvent
1 parent 219d4a5 commit 04989e5

File tree

8 files changed

+12
-4
lines changed

8 files changed

+12
-4
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ plugins {
4040
group "org.logstash.filters"
4141
version "${new File("VERSION").text.trim()}"
4242

43-
String junitVersion = '5.9.2'
43+
String junitVersion = '5.11.2' // at least 5.11 is needed to use @FieldSource with @ParameterizedTest
4444
String maxmindGeoip2Version = '2.17.0'
4545
String maxmindDbVersion = '2.1.0'
4646
String log4jVersion = '2.17.1'

src/test/java/org/logstash/filters/geoip/GeoIPFilterTest.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.junit.jupiter.api.Test;
44
import org.junit.jupiter.params.ParameterizedTest;
5+
import org.junit.jupiter.params.provider.FieldSource;
56
import org.junit.jupiter.params.provider.ValueSource;
67
import org.logstash.Event;
78

@@ -25,6 +26,12 @@ class GeoIPFilterTest {
2526
private static final String SOURCE_FIELD = "ip";
2627
private static final String TARGET_FIELD = "data";
2728

29+
// used as parameters of givenDatabaseWithCustomizedFieldWhenItsAccessedTheCustomizedIPShouldntThrowAnyErrorAndReportTheLookupAsFailure
30+
@SuppressWarnings("unused")
31+
static Path[] databases = {MaxMindDatabases.GEOIP2_COUNTRY, MaxMindDatabases.GEOIP2_ANONYMOUS_IP,
32+
MaxMindDatabases.GEOIP2_ENTERPRISE, MaxMindDatabases.GEOIP2_DOMAIN, MaxMindDatabases.GEOIP2_ISP,
33+
MaxMindDatabases.GEOLITE2_ASN};
34+
2835
@ParameterizedTest
2936
@ValueSource(booleans = {true, false})
3037
void handleEventWithGeoIp2CityDatabaseShouldProperlyCreateEvent(boolean ecsEnabled) {
@@ -266,9 +273,10 @@ void handleEventWithNoCustomFieldsShouldUseDatabasesDefaultFields() {
266273
}
267274
}
268275

269-
@Test
270-
void givenDatabaseWithCustomizedFieldWhenItsAccessedTheCustomizedIPShouldntThrowAnyErrorAndReportTheLookupAsFailure() {
271-
try (final GeoIPFilter filter = createFilter(MaxMindDatabases.GEOIP2_COUNTRY, true, Collections.emptyList())) {
276+
@ParameterizedTest
277+
@FieldSource("databases")
278+
void givenDatabaseWithCustomizedFieldWhenItsAccessedTheCustomizedIPShouldntThrowAnyErrorAndReportTheLookupAsFailure(Path geoDatabase) {
279+
try (final GeoIPFilter filter = createFilter(geoDatabase, true, Collections.emptyList())) {
272280
final RubyEvent rubyEvent = createRubyEvent("216.160.83.60");
273281
assertFalse(filter.handleEvent(rubyEvent), "Lookup of data point with invalid custom fields should report as failed");
274282
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)