Skip to content

Commit

Permalink
fix: Matching rules were not being applied to repeated header values
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Jun 26, 2023
1 parent 28d544e commit f0a4f6c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import au.com.dius.pact.core.model.matchingrules.MinMaxEqualsIgnoreOrderMatcher
import au.com.dius.pact.core.model.matchingrules.TypeMatcher
import au.com.dius.pact.core.model.matchingrules.ValuesMatcher
import au.com.dius.pact.core.model.parsePath
import au.com.dius.pact.core.support.padTo
import io.pact.plugins.jvm.core.PluginConfiguration
import mu.KLogging

Expand Down Expand Up @@ -190,7 +191,7 @@ object Matching : KLogging() {
return e.entries.fold(listOf()) { list, values ->
if (a.containsKey(values.key)) {
val actual = a[values.key].orEmpty()
list + HeaderMatchResult(values.key, values.value.mapIndexed { index, headerValue ->
list + HeaderMatchResult(values.key, values.value.padTo(actual.size).mapIndexed { index, headerValue ->
HeaderMatcher.compareHeader(values.key, headerValue, actual.getOrElse(index) { "" }, context)
}.filterNotNull())
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ class HeaderMatcherSpec extends Specification {
"Expected 'XYZ' to match 'X=.*', Expected 'XYZ' to match 'A=.*', Expected 'XYZ' to match 'B=.*'"
}

def "matching headers - applies the matching rule to all header values"() {
given:
context.matchers.addRule('HEADER', new RegexMatcher('\\d+'))

expect:
Matching.INSTANCE.compareHeaders([HEADER: ['100']], [HEADER: ['100', '20x', '300']], context)*.result*.mismatch ==
[["Expected '20x' to match '\\d+'"]]
}

@Unroll
@SuppressWarnings('LineLength')
def "matching headers - content type header - be true when #description"() {
Expand Down

0 comments on commit f0a4f6c

Please sign in to comment.