From 28d544efc031c24c8c189ac2f52a9b240468cae0 Mon Sep 17 00:00:00 2001 From: Ronald Holshausen Date: Mon, 26 Jun 2023 14:25:33 +1000 Subject: [PATCH] fix: Matching rules were not being applied to repeated query parameters --- .../au/com/dius/pact/core/matchers/QueryMatcher.kt | 5 ++++- .../dius/pact/core/matchers/QueryMatcherSpec.groovy | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/core/matchers/src/main/kotlin/au/com/dius/pact/core/matchers/QueryMatcher.kt b/core/matchers/src/main/kotlin/au/com/dius/pact/core/matchers/QueryMatcher.kt index c9dcdd38b4..25e7cc55fe 100644 --- a/core/matchers/src/main/kotlin/au/com/dius/pact/core/matchers/QueryMatcher.kt +++ b/core/matchers/src/main/kotlin/au/com/dius/pact/core/matchers/QueryMatcher.kt @@ -1,5 +1,6 @@ package au.com.dius.pact.core.matchers +import au.com.dius.pact.core.support.padTo import mu.KLogging import org.atteo.evo.inflector.English @@ -33,7 +34,9 @@ object QueryMatcher : KLogging() { path: List, context: MatchingContext ): List { - return expected.mapIndexed { index, value -> index to value } + return expected + .padTo(actual.size) + .mapIndexed { index, value -> index to value } .flatMap { (index, value) -> when { index < actual.size -> compare(parameter, value, actual[index], context) diff --git a/core/matchers/src/test/groovy/au/com/dius/pact/core/matchers/QueryMatcherSpec.groovy b/core/matchers/src/test/groovy/au/com/dius/pact/core/matchers/QueryMatcherSpec.groovy index b752b76a38..562e9f7936 100644 --- a/core/matchers/src/test/groovy/au/com/dius/pact/core/matchers/QueryMatcherSpec.groovy +++ b/core/matchers/src/test/groovy/au/com/dius/pact/core/matchers/QueryMatcherSpec.groovy @@ -2,6 +2,7 @@ package au.com.dius.pact.core.matchers import au.com.dius.pact.core.model.matchingrules.DateMatcher import au.com.dius.pact.core.model.matchingrules.MatchingRuleCategory +import au.com.dius.pact.core.model.matchingrules.RegexMatcher import spock.lang.Specification class QueryMatcherSpec extends Specification { @@ -34,4 +35,14 @@ class QueryMatcherSpec extends Specification { ['1000-01-01', '2000-01-01'], ['2000-01-01', '2000x-01-03'], context)*.mismatch == ["Expected '2000x-01-03' to match a date of 'yyyy-MM-dd': Unable to parse the date: 2000x-01-03"] } + + def 'applies matching rules to multiple parameter values'() { + given: + context.matchers.addRule('a', new RegexMatcher('\\d+')) + + expect: + QueryMatcher.compareQuery('a', + ['100'], ['100', '200', '300x'], context)*.mismatch == + ["Expected '300x' to match '\\d+'"] + } }